2016-06-30 352 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); 
相关问题