我正在尝试创建一个JVM
通过 Windows 服务但JNI_CreateJavaVM
总是失败。这是我的代码,
DWORD WINAPI InvokeMain(LPVOID lpParam) {
// HACK to hang the function
while(1) {
if( (_access( "e:\\file", 0 )) != -1 ) {
break;
}
}
//Load the JVM Dll
HINSTANCE ghDllInstance = LoadLibrary(L"E:\\jdk1.6.0_26\\jre\\bin\\server\\jvm.dll");
if( ghDllInstance == 0) {
Log("Failed to load jvm dll\n");
return FALSE;
}
//resolve the function pointer JNI_CreateJVM
CreateJavaVM createJVMStart = (CreateJavaVM)GetProcAddress(ghDllInstance, "JNI_CreateJavaVM");
JavaVMOption options[2];
options[0].optionString = "-Djava.class.path=e:\\win\\product\\lib"; // application class path
options[1].optionString = " start";
JavaVMInitArgs vm_args;
vm_args.version = JNI_VERSION_1_6; //JNI Version 1.4 and above
vm_args.options = options;
vm_args.nOptions = 2;
vm_args.ignoreUnrecognized = JNI_FALSE;
//Create the JVM
JavaVM *vmStart;
JNIEnv *env;
jint res = createJVMStart(&vmStart, (void **)&env, &vm_args);
if (res < 0) {
Log( "Error creating JVM");
return FALSE;
}
return TRUE;
}