I use the JNI to start a Java Application out of C. While this is quickly done as long as I'm using a console Application, whith a Swing-GUI things get a bit tricky.
To keep the application "alive" I use a while loop that just runs as long as GUI is not closed. While this loop runs it always requests, if the application is still running by requesting a boolean value.
while(javaRunning){
if(JNI_FALSE == env->CallBooleanMethod(obj, boolMethod))
javaRunning = false;
}
This value is changed when the Java function WindowClosing(Event) is called to indicate that the user closes the window.
Unfortunately this does not work if I close the window. The C-Application still tries to request the boolean value, even though the window is already closed. It obviously is not able to fetch the boolean before the window closes. A better approach would be to call the C-Code from Java to inform it about the "WindowClosing" event.
Well as far as I can see, this would be possible if the C-Code is loaded by Java (using a DLL) but not via the invocation interface were C instanciates and starts the Java application. Maybe anyone knows how to get around with this.