Von C++ eine C++/Cli Klasse aufrufen



  • Hallo zusammen

    Ich habe mir mit Visual Studio .NET 2005 ein normales C++ Projekt erzeugt und dort folgende Datei geschrieben:

    #include <jni.h>
    
    #include "../../Java/helloworld/bin/helloworld_HelloWorld.h"
    
    #include "../../CppCli/helloworld/HelloWorldC.h"
    //#pragma managed(pop)
    
    JNIEXPORT void JNICALL Java_helloworld_HelloWorld_displayHelloWorld(JNIEnv *jn, jobject jobj) {
    
        // Instantiate the C++/CLI class.
    
        HelloWorldC* t = new HelloWorldC();
    
        // The actual call is made. 
    
        t->callCSharpHelloWorld();
    }
    

    Danach hab ich die Klasse HelloWorldC.cpp als C++/Cli Datei geschrieben

    #using <mscorlib.dll>
    #using "../../CSharp/helloworld/CSharpHelloWorld.netmodule"
    
    using namespace System;
    
    public ref class HelloWorldC
    {
    	public:
    		CSharpHelloWorld^ t;
    
    		HelloWorldC()
    		{
    			t = gcnew CSharpHelloWorld();
    		}
    
    		void callCSharpHelloWorld()
    		{
    			t->displayHelloWorld();
    		}
    };
    

    , welche sich auch mit

    cl /clr HelloWorldC.cpp /link /dll
    

    kompiliern lässt.

    Die CSharp Klasse hab ich auch geschrieben und kompiliert. Die Pfade stimmen auch alle.
    Wenn ich allerdings den Build über Visual Studio starten will sagt der Compiler:

    HelloWorldC.cpp : fatal error C1190: managed targeted code requires a '/clr' option
    

    Ich hab die Properties der Datei HelloWorld.cpp so gelassen wie sie am Anfang eingestellt waren und die von HelloWorldC.cpp hab ich unter C/C++ > 'Compile with Common Language Runtime' auf 'Common Language Runtime Support (/clr)' gesetzt.
    Ausserdem hab 'Enable C++ Exceptions' ausgeschaltet und 'Runtime Library' auf 'Multi-threaded Debug Dll (/MDd)' gesetzt.

    Der Fehler bleibt allerdings trotz allem.
    Das sind meine ersten gehversuche mit C++/Cli und ich wäre sehr froh wenn mir hier jemand weiter helfen könnte.

    Danke schonmal im vorraus.

    Viel Grüße,
    Michael



  • Ich danke schonmal vorher soll das heissen. Keine Ahnung wo die Sterne bei im vorraus herkommen...

    Fehlen noch irgendwelche Angaben?



  • Lackmeier schrieb:

    Ich danke schonmal vorher soll das heissen. Keine Ahnung wo die Sterne bei im v****** herkommen...

    einige wenige wörter werden vom forum ausgesternt, damit sich diese rechtschreibfehler nicht so stark vermehren.
    siehe auch standart



  • Ok ich schlag bei Gelegenheit mal im Duden nach. 🙂

    Nur steht da leider nicht drin wie ich das Programm kompiliert krieg...


Log in to reply