Java to MFC and back asynchronously
843829Oct 19 2008 — edited Oct 20 2008Hi all, the setup I want to get functioning is as follows:
There is a Java application that initializes a C++ application (this part is taken care of). Then the Java application has to send messages to the C++ (MFC) application. For this purpose I have created a JNI based dll that sends data received from the Java app to the MFC one.
The problems start when I try to send messages from the MFC part to the Java program. I have tried a few approaches but none has worked.
Using JNI_GetCreatedJavaVMs has not worked since it has returned no instance of a JVM although the Java program was still running.
I had no luck either caching a pointer of the JVM using the onLoad method when the JNI calls commence from the Java app. It seems that this pointer is not valid in a process other than the one initiated by Java calling native code.
There is one option I have not tried yet, which is creating a JVM from native code but I am worried that from that I won't be able to get hold of the same instance of the running Java application...
Does anyone know a good way to handle this situation? I need to work with the exact same Java and MFC application instances all the time. Many thanks.