Please help, invoking CreateJavaVM via a function pointer is returning -3, but I'm not sure why.
When my PATH is setup up to include the jvm.dll and I invoke JNI_CreateJavaVM() directly, it works fine. But I want it to work regardless of my PATH setting, so I am trying to use LoadLibrary and dynamically load the jvm.dll and then a function pointer to invoke CreateJavaVM().
The LoadLibrary returns non-NULL result, the GetProcAccress() returns non-null, but when I invoke the pointer to the CreateJavaVM call, it returns -3. I know -3 is JNI_EVERSION error, but any ideas what is wrong with the code below, such that it would give me this error?
Currently my code is as follows:
typedef jint (JNICALL CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);
JavaVM *m_jvm;
JNIEnv *m_env;
SetDllDirectory(L"C:\\Program Files\\Java\\jdk1.6.0_20\\jre\\bin\\client");
HINSTANCE hVM = LoadLibrary(L"jvm.dll");
if ( hVM == NULL ) {
// report error
}
CreateJavaVM_t *pfnCreateJavaVM = (CreateJavaVM_t*)GetProcAddress(hVM, "JNI_CreateJavaVM");
#ifdef JNI_VERSION_1_6
char cpChars[1024] = {0};
sprintf_s(cpChars, "-Djava.class.path=%s", classPath); // classpath is defined elsewhere
JavaVMOption options[1];
options[0].optionString = cpChars;
JavaVMInitArgs vm_args;
vm_args.version = JNI_VERSION_1_6;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
pin_ptr<JNIEnv*> env = &m_env;
pin_ptr<JavaVM*> jvm = &m_jvm;
int result = pfnCreateJavaVM(jvm, (void**)env, &vm_args);
// This is where the failure occurs. result is -3 for some reason here...why?
For some reason, pfnCreateJavaVM is returning -3, but I'm not sure why? Any ideas what is wrong with this code, such that it would give me a -3?
Thanks in advance,
Bill