I'm not sure if this should be posted here or in the C++ forums, but
I'm figuring it is more likely that there is someone else here who has
run into similar issues before.
I am using the invocation api to access my java classes from a COM
based C++ application.
I know that my routines for creating the JVM are correct. When I run
it using a tester app on my machine, it works perfectly.
When I add it to the full flavored C++ application, I run into 1 of 2
problems depending on where I try to create the JVM.
If I call out to my start JVM function to get a handle to the JNIEnv
from the preInitialize method of the COM class, which is where the COM
classes are registered and constructed, all parts of the java
application and jni connection work 100% correctly. The problem is
that this messes up the onscreen graphics of one of the other COM
classes to the point where they don't function and the machine gives me
a Win32 error code of 6, which is an end of file error (no idea why
even after looking at the code and trying to watch it with utilities)
Since I havent been able to fix the graphics problem, I have tried
pulling the start JVM function into the event handler function where
the JNI connection is actually used. When I use it there, the exact
same JNI_CreateJavaVM function returns a null value 100% of the time
for the JNIEnv.
I haven't been able to find much information on what causes the
JNI_CreateJavaVM to fail, so any suggestions would be appreciated, nor
do I understand the process that it goes through under the hood to
create the environment, for example how the threading of it works. Is
it taking over whatever the current thread in the c++ code is when I
create it?
I would post a SSCCE, but I don't believe that the problem is in my
code, rather I think it is in my lack of understanding of all the
things that are going on behind the scenes.
Any insight would be greatly appreciated.
Best,
Josh Falter
Chris Uppal - 10 Jan 2006 10:49 GMT
> If I call out to my start JVM function to get a handle to the JNIEnv
> from the preInitialize method of the COM class, which is where the COM
> classes are registered and constructed, all parts of the java
> application and jni connection work 100% correctly. The problem is
> that this messes up the onscreen graphics of one of the other COM
> classes to the point where they don't function
That sounds as if you have an old-fashioned, pointer-related bug somewhere.
I.e. not a problem with the way you are using COM or JNI as such.
That's not to say that you might not have such problems /too/. In fact I would
be very wary of mixing COM and JNI since both have very specific laws about how
they are used (mostly to do with threads) and I don't know nearly enough about
COM to be sure that I was doing things "right" even if I was reasonably sure I
wasn't abusing JNI.
-- chris