> I then init the dll by calling a method in the c++ dll like this:
> (trying to save the references for env and obj)
[quoted text clipped - 7 lines]
> jObj = env->NewGlobalRef(obj);
> }
Don't attempt to save the JNIEnv pointer for use from a different
context, it will crash as you have discovered. Read the documentation
for the invocation API (at the end of the JNI spec) for information
about this.
Saving the object reference is ok, just remember to release the global
reference when you no longer need it.
> I have a function in my dll which I want to call a method (void
> doTextOut(int i)) in my Java class that loaded the dll, it looks
[quoted text clipped - 5 lines]
> jEnv->CallVoidMethod(jObj, mid);
> }
You need to attach "this" thread to the JVM to get a valid JNIEnv* for
use in this context. Use JNI_GetCreatedJavaVMs() and
AttachCurrentThread(), part of the invocation API.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
castillo.bryan@gmail.com - 28 Jun 2005 15:57 GMT
> > I then init the dll by calling a method in the c++ dll like this:
> > (trying to save the references for env and obj)
[quoted text clipped - 29 lines]
> use in this context. Use JNI_GetCreatedJavaVMs() and
> AttachCurrentThread(), part of the invocation API.
As an alternative you can also used the JNI_OnLoad function to save the
JavaVM pointer, instead of using JNI_GetCreatedJavaVMs.
http://java.sun.com/j2se/1.3/docs/guide/jni/jni-12.html#JNI_OnLoad
> /gordon
>
> --
> [ do not email me copies of your followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e
Gitta Zahn - 28 Jun 2005 20:48 GMT
>>void update(){
>> jclass cls = jEnv->GetObjectClass(jObj);
[quoted text clipped - 5 lines]
> use in this context. Use JNI_GetCreatedJavaVMs() and
> AttachCurrentThread(), part of the invocation API.
As alternative you could use the operation GetEnv()
within the operation update()
http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html#GetEnv
This is at least necessary if you have multiple native threads
attached at the JVM.
Gitta