Re: Java <-> MFC?
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Apr 2005 19:18:30 +0100
Tim Ward wrote:
> (1) That's OK for me hacking around but obviously not useful for
> deployment, when the user might have who-knows-which version of the JRE
> installed who-knows-where. The installation process for my MFC app
> couldn't add the location of jvm.dll to the path because it hasn't a clue
> where it is (even if I wanted to mess with the user's path for such a
> small new feature of my app, which I don't). How do people solve this one?
It's generally thought that the best way to deploy Java-based, or
Java-including, standalone apps is to include the JRE as part of your
deployment. If you do that then you can hardwire the DLL location.
If you don't want to do that, or if you want to give your users the option of
using their own installed JRE, then you can look in the registry. Sun Java
installations follow the pattern that
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime
Environment\CurrentVersion
is the string name of the current version. "1.5" on my machine. Under
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\<version>
you should find the JavaHome and the RuntimeLib.
There are other cross-refs between the registry entries which should be pretty
obvious if you have access to machine(s) with more than one JRE installled.
The JDK installations use similar pointers, but you probably won't want to use
them in this context.
Other vendors' JVMs may use similar -- but, of course, not /very/ similar --
patterns. E.g. both IBM and BEA do.
> (b) closing the Swing GUI in the normal way (click on the window close
> box) ends up in a (Java) call of System.exit(0); which takes down the
> calling C++ application! No! No! Surely not! How could I possibly want
> that?? Closing the Java application should take down the Java
> application, and I'm not too bothered about whether it takes down the
> Java VM as well, but what on earth was going through the head of the
> person who decided it would be a good idea to take down the calling
> native application as well?????
Fair question. When you get more used to JNI you'll come to hate the Sun
JVM/JNI programmers with a great passion.
For now, I think that ensuring that you set the JFrame's
setDefaultCloseOperation() to DISPOSE_ON_CLOSE (instead of EXIT_ON_CLOSE, or
whatever it's called) will probably do.
You /may/ be able to prevent the JVM killing the calling app by setting an exit
hook (part of JNI but I forget the API just for the minute). I've had no luck
with that myself -- it just deadlocks my application, but then my application
does some rather unusual things with threads, so that may not be the general
experience.
You /may/ be able to prevent it by setting a security policy that forbids calls
to System.exit() (and friends) but I haven't experimented with that myself.
A couple of other potential gotchas to watch out for.
Once you have closed down the JVM, you cannot start a new one from the same
application. So you just get one, and you have to make it last...
Sun's programmers are careless about the floating point exception flags. If
you are doing much/any floating point in your C/C++ application, then you
should watch out for the JVM crashing because makes assumptions about the
underflow/overflow environment that it will find itself in.
I /think/ there may be problems with the -Xcheck:jni flag in the `1.5.0 JVM.
That flag worked fine in the 1.4 series JVMs, and was very useful. But I've
found that turning it on with the 1.5.0 version causes the JVM to flag JNI
errors (and -- of course -- therefore kill my application instantly) when I'm
reasonably certain that I'm doing nothing wrong.
-- chris
.
- Follow-Ups:
- Re: Java <-> MFC?
- From: Tim Ward
- Re: Java <-> MFC?
- References:
- Java <-> MFC?
- From: Tim Ward
- Re: Java <-> MFC?
- From: Daniel Dyer
- Re: Java <-> MFC?
- From: Tim Ward
- Re: Java <-> MFC?
- From: Daniel Dyer
- Re: Java <-> MFC?
- From: Tim Ward
- Java <-> MFC?
- Prev by Date: Re: Java on Big Memory Machines
- Next by Date: Re: How do you store a variable on the server?
- Previous by thread: Re: Java <-> MFC?
- Next by thread: Re: Java <-> MFC?
- Index(es):
Relevant Pages
|