I have written a little MS Win32 DLL that makes use of some Java API I've packed into a jar using the JNI mechanism. I've released this DLL to a customer who has the requirement due to requests from other parts of his program to load and unload my DLL for each call. He's doing something like this:
(*proc)(...); // call my DLL method which will forward the request to a Java VM
In my DLL the public Java VM to use is searched in the registry etc. Then a call to the JNI method CreateJavaVM() is made. This call returns the address of the Java VM to use, some environment structures and sets the classpath extension in order to find my jar. Then the Java class and method are searched and finally called. After that I call DetachCurrentThread() (works without) and DestroyJavaVM().
This all works fine for the first time. But when executed the seconde time the call to CreateJavaVM() returns with JNI_ERR (-1). Loading the DLL once, calling the Java method as often as desired and then freeing the DLL once works fine. But doing this the 2nd time leads to the same error.
Does anybody know what to do in order to enable my DLL to be loaded and freed as often as desired and still get the VM created successfully? This would be of great help for me. Any suggestions are welcome.
Thanx in advance