Multiple Calls to JNI_CreateJavaVM
843829Aug 27 2004 — edited Sep 2 2004I have been searching the forum and elsewhere for a resolution to the problem of calling JNI_CreateJavaVM multiple times - you can only call JNI_CreateJavaVM once, subsequent calls will fail. The following resolution was posted as a solution
"Does your dll link directly with jvm.dll and call JNI_CreateJavaVM directly, or are you loading jvm.dll via LoadLibrary and GetProcAddress? If the former, then jvm.dll could be unloading when your dll unloads, which might cause the weirdness. Try loading jvm.dll dynamically and then never unload it (via FreeLibrary) so it stays loaded for the lifetime of the main process.
I've implemented exactly this scheme (with Sun 1.4.2_03) and it works fine."
I have tried this and I'm getting the same error that I get when I call JNI_CreateJavaJVM directly. I have created a C++ dll that exports a Parser class. Each new instance of the class tries to load the jvm.
The code below is in my Parser class constructor. Can anyone point out what I am doing wrong.
Thanks in advance
HINSTANCE handle;
if((handle == LoadLibrary(JVM_DLL))==NULL)
{
//throw error
}
typedef jint (JNICALL P_JNI_CreateJavaVM)(JavaVM * pvm, void ** penv, void * args);
P_JNI_CreateJavaVM createJavaVM = (P_JNI_CreateJavaVM)(GetProcAddress(handle,"JNI_CreateJavaVM");
if(createJavaVM==NULL)
{
//throw error
}
m_res = (*createJavaVM)(&m_jvm,(void **)&m_env, &m_vm_args);