jni jvm



  • hallo,

    #include "stdafx.h" 
    #include "jni.h"
    #include "windows.h" 
    
    typedef jint (WINAPI* JNI_CREATEJAVAVM)(JavaVM **pvm, void ** penv, void *args); 
    
    int main(int argc, char* argv[]) 
    { 
       JavaVMInitArgs vm_args; 
       JavaVMOption options[10]; 
       JavaVM* jvm; 
       JNIEnv* env; 
    
       options[0].optionString = "-Djava.compiler=NONE"; 
       options[1].optionString = "-Djava.class.path=D:/programme/eclipse/workspace/helloworld"; 
    
       vm_args.version  = JNI_VERSION_1_4; 
       vm_args.nOptions = 2; 
       vm_args.options  = options; 
       vm_args.ignoreUnrecognized = JNI_FALSE; 
       JNI_CREATEJAVAVM JNI_CreateJavaVM = 0; 
    
       HMODULE hLib = LoadLibrary(_T("E:/c_progs/nativ_c/nativ_c/jvm.dll")); 
       if(hLib==NULL){
       printf("%d",GetLastError());
       }
    
       JNI_CreateJavaVM = (JNI_CREATEJAVAVM) GetProcAddress (hLib, "JNI_CreateJavaVM"); 
       if(JNI_CreateJavaVM==NULL){
       printf("%d",GetLastError());
       }
    
       long status  = JNI_CreateJavaVM(&jvm, (void**) &env, &vm_args); 
       if  (status != JNI_OK) 
       { 
          printf("Failed creating JVM. Error: %d\r\n", status); 
       } 
       else 
       { 
          printf("JVM created\r\n"); 
       } 
    
       return 0; 
    }
    

    der wert von status ist -1. kann mir da jemand weiter helfen und wer ne kurze einfache erklärung für diesen typdef hat kann die ruhig auch posten, kenne mich nämlich mit c/c++ noch nicht so gut aus, ist aber nebensächlich.



  • das mit dem status hat sich geklährt musste die dll aus ihrem ursprünglichen Verzeichnis aufrufen. 🙂


Anmelden zum Antworten