Calling a Java method from C++ via JNI problem.



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
.



Relevant Pages

  • Re: Java programmer lured back by .Net (Questions)
    ... in .NET a form is simply a class so yes it could easily be placed into a DLL and then use Ngen to make a native image of it. ... Of course it learned a lot from Java, and improved upon many things which Java is slowly catching up on. ... As far as code security you're in the same boat as Java since it compiles down to MSIL instead of bytecode of which both can reverse engineered very easily. ... I would like to be able to place my executable on my remote server and then "load" the executables on demand from accross the internet - so that there are no executables on the local machine for prying eyes to reverse engineer. ...
    (microsoft.public.dotnet.distributed_apps)
  • Calling a Java method from C++ via JNI problem.
    ... I am having some real difficulties calling a Java method from C++ ... I then init the dll by calling a method in the c++ dll like this: ... (trying to save the references for env and obj) ...
    (comp.lang.java.programmer)
  • Re: Java programmer lured back by .Net (Questions)
    ... in .NET a form is simply a class so yes it could easily be placed into a DLL and then use Ngen to make a native image of it. ... Of course it learned a lot from Java, and improved upon many things which Java is slowly catching up on. ... As far as code security you're in the same boat as Java since it compiles down to MSIL instead of bytecode of which both can reverse engineered very easily. ... My backend is pure Java running on Unix - but because SWING is so ...
    (microsoft.public.dotnet.distributed_apps)
  • Re: JNI EXCEPTION_ACCESS_VIOLATION
    ... I am not experienced in coding a dll and access it via ... Java, but, I would say to you that, if you do not mind, try to use the ... The code will crash when running under XP Service Pack 2 ... The code will NOT crash when running under Windows 2000 Service Pack 4 ...
    (comp.lang.java.programmer)
  • Re: JNI interoperating with .net DLL?
    ... CLR DLL which export extern "C" function API to call 3. ... It works by calling as a standalone java class. ... what I need is to call functions in this class from a TOMCAT environment. ... I realised that if I remov the "Actual .NET" function call in the CLR DLL in step 2. ...
    (comp.lang.java.programmer)