I have a Windows MFC application that:
(1) Loads the JVM ( JNI_CreateJavaVM() )
(2) Attaches the main thread to the JVM ( AttachCurrentThread() )
(3) Loads some Java classes and methods ( FindClass() and GetMethodID() / GetStaticMethodID() )
(4) Registers some native callbacks for use by Java code ( RegisterNatives() )
(5) Separates the thread from the JVM ( DetachCurrentThread() )
(6) Destroys the JVM ( DestroyJavaVM() )
All of the above functions are executed every time I launch the application. I know that they succeed because, in addition to the above, I interact with the application and successfully call static Java methods, and these Java methods successfully call my own callbacks. My application exits gracefully, and it is sure that the expected Java functions and native callbacks are complete.
However, every time I run the application, the call to JNI_CreateJavaVM() fails (without populating JavaVM * ). Absolutely nothing changes between application runs . I just run it once (successfully, without even doing anything other than the above 6 steps), legally terminate, run it again, and it fails, back and forth. There are no exceptions for success and failure. I can run it dozens of times, and it oscillates at exactly another time between success and failure in the JNI_CreateJavaVM() .
If necessary, I will enclose more code. However, I hope someone has an idea of ββwhat I have provided. (Note: this is the BCGSoft MFC property specification application, although I strongly doubt it is important.)
java c ++ visual-studio visual-studio-2010 jni
Dan nissenbaum
source share