2016-06-30 124 views
0

我想在C++應用程序中使用Voce。現在,在幾句頭,更具體的void init()有一部分像這樣的:JNI_CreateJavaVM崩潰C++應用程序沒有錯誤信息

vm_args.nOptions = 2; 
// Setup the VM options. 
// TODO: check out other options to be used here, like disabling the 
// JIT compiler. 
JavaVMOption options[2]; 
// Add the required Java class paths. 
std::string classPathString = "-Djava.class.path="; 
classPathString += vocePath; 
classPathString += "/voce.jar"; 
char s[1024]; 
sprintf(s, classPathString.c_str()); 
options[0].optionString = s; 
options[0].extraInfo = NULL; 

// Add an option to increase the max heap size. (1) 
char x[1024] = "-Xmx256m"; 
options[1].optionString = x; 
options[1].extraInfo = NULL; 
//options[1].optionString = "-Djava.compiler=NONE"; // Disable JIT. 
//options[1].optionString = "-verbose:gc,class,jni"; 
vm_args.options = options; 
//vm_args.ignoreUnrecognized = JNI_FALSE; 

// Create the VM. (2) 
status = JNI_CreateJavaVM(&internal::gJVM, (void**)&internal::gEnv, &vm_args); 

如果我嘗試這樣運行它,它崩潰。如果我在(1)之後將所有內容都放入註釋中,它會運行。之後,如果我只是將JNI_CreateJavaVM放入註釋(2)中,它也會運行。如果我從崩潰中直接將(2)放入註釋中,它會再次崩潰。我需要走過(1)和(2)的路,然後是(2)。但是,由於Voce需要JavaVM,這是一個問題。顯然。我的猜測是,我需要一些dll,目前我有與main.cpp相同的文件夾中的jvm.dll,但與voce.h不一樣。

回答

0

如果您對已安裝的jvm.dll使用動態鏈接和加載,這應該有效。

typedef jint(JNICALL *pCreateJavaVM)(JavaVM **, void**, void *); 

HINSTANCE hInstance = LoadLibrary(L"C:\\Program Files\\Java\\jre1.8.0_77\\bin\\server\\jvm.dll"); 
pCreateJavaVM CreateJavaVM = (pCreateJavaVM)GetProcAddress(hInstance, "JNI_CreateJavaVM"); 

jint res = CreateJavaVM(&vm, (void **)&env, &vm_args); 
相關問題