my dog learned polymorphism*
The moose likes Java in General and the fly likes HELP: Launching JVM from Visual C++ problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "HELP: Launching JVM from Visual C++ problem" Watch "HELP: Launching JVM from Visual C++ problem" New topic
Author

HELP: Launching JVM from Visual C++ problem

Fabien Tronche
Greenhorn

Joined: Feb 28, 2003
Posts: 4
Hey there,
Problem: I'm trying to launch a .jar file from a Visual C++ project. I've got a MFC application with a standard CDialog. When I click a button on this dialog, I invoke the JVM using JNI, passing all the proper arguments (I think).
Result: The Java app contained in the .jar file starts properly but the processing doesn't come back to my C++ application. And when I close the Java app, the C++ app crashes.
I've tried calling jvm->DetachCurrentThread(); defore to destroy the jvm but with no success.
Please help me on this, I'm going completly insane I can provide source code if it can help...
Thanks in advance,
Fabien.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Fabien,
A little more information would be helpful here. What exactly are you trying to accomplish? Do you want the Java app to be detached from the native app or do you want to control/communicate with the Java app from the native app or vice-versa?
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Fabien Tronche
Greenhorn

Joined: Feb 28, 2003
Posts: 4
Hi Michael,
Thanks for the reply. Here is what I'd like to do:
I have a MFC application that:
1 - Displays a splash screen
2 - Start the JVM and launch the .jar file
3 - Hides the spalsh screen
4 - Exits
I want the java app to be detached, so that it can still run even after the MFC app quits. I don't need any communication between the two.
Thanks,
Fabien.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Fabien,
Are you starting the Java app, with CreateProcess()? If not, how?
Michael Morris
Fabien Tronche
Greenhorn

Joined: Feb 28, 2003
Posts: 4
Michael,
I'm starting the java app using the JNI methods (JNI_CreateJavaVM, ...).
That's where the problem is, i can create the Java VM, call the main method inside the Main-class of the .jar file.
This starts the java app, but then it seems that I can't detached the Java VM from the current process (C++ app).
Whether I would like to finish the C++ app and still have the java app running normally.
Thanks,
Fabien.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Fabien,
You might try writing a small bootstrap program that launches the JVM and call it from your MFC app with CreateProcess() istead of launching the JVM directly from the MFC app. It's been a while since I did any C++ programming in Windows and I can't remember if the child process can run after the parent exits when calling CreateProcess(). In Unix, you can detach an external process with fork(). You may be able to do that with Windows' spawn().
Hope this helps,
Michael Morris
Michael Morris
Fabien Tronche
Greenhorn

Joined: Feb 28, 2003
Posts: 4
Hi Michael,
Thanks for the help, I think I will use CreateProcess for now and use the command line call but in the future I'd still like to use the JNI functions. It seems that there are some problem with message processing in the C++ code when calling the JNI...
I'll keep looking and I'll post any solution I can find...
Thanks again for the help, much appreciated!
Fabien.
 
GeeCON Prague 2014
 
subject: HELP: Launching JVM from Visual C++ problem