S
Sambucus
Hi all,
I am having some real difficulties calling a Java method from C++
code.
I load my c++ dll from java using:
static {
System.loadLibrary("libname");
}
I then init the dll by calling a method in the c++ dll like this:
(trying to save the references for env and obj)
static JNIEnv *jEnv;
static jobject jObj;
JNIEXPORT void JNICALL Java_poker_jni_JavaClassName_init(JNIEnv *env,
jobject obj){
jEnv = env;
jObj = env->NewGlobalRef(obj);
}
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 like
this:
void update(){
jclass cls = jEnv->GetObjectClass(jObj);
jmethodID mid = jEnv->GetMethodID(cls, "doTextOut", "(I)V");
jEnv->CallVoidMethod(jObj, mid);
}
this method is called from my WndProc callback function.
When I do this the JVM will crash.
If I try to do exactly the same thing as update() in the JNIEXPORT
void JNICALL Java_poker_jni_JavaClassName_init(JNIEnv *env, jobject
obj) function it works!?! But the thing is that I really need to do it
from update()
Any suggestion on what I am doing wrong, or is this something that is
not even possible to do with JNI?
Any help would be greatly appreciated!
Best Regards
AET
I am having some real difficulties calling a Java method from C++
code.
I load my c++ dll from java using:
static {
System.loadLibrary("libname");
}
I then init the dll by calling a method in the c++ dll like this:
(trying to save the references for env and obj)
static JNIEnv *jEnv;
static jobject jObj;
JNIEXPORT void JNICALL Java_poker_jni_JavaClassName_init(JNIEnv *env,
jobject obj){
jEnv = env;
jObj = env->NewGlobalRef(obj);
}
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 like
this:
void update(){
jclass cls = jEnv->GetObjectClass(jObj);
jmethodID mid = jEnv->GetMethodID(cls, "doTextOut", "(I)V");
jEnv->CallVoidMethod(jObj, mid);
}
this method is called from my WndProc callback function.
When I do this the JVM will crash.
If I try to do exactly the same thing as update() in the JNIEXPORT
void JNICALL Java_poker_jni_JavaClassName_init(JNIEnv *env, jobject
obj) function it works!?! But the thing is that I really need to do it
from update()
Any suggestion on what I am doing wrong, or is this something that is
not even possible to do with JNI?
Any help would be greatly appreciated!
Best Regards
AET