JNI Invocation interface

T

Tim

Having created a JVM from C++ using the Invocation interface, how can I
call back from the Java to my C++ code? I am sure this must be simple
but I can't find a reference to how to do it, and I am up against the
clock

I am fine with using JNI to load & call a native DLL from Java, but
here I am wanting to call back to the invoking C++ code - ie I am not
using system.loadlibrary.

On a slightly different tack, if I invoke the JVM frrm a DLL using the
invocation api, then use system.loadlibrary with that dll name, does
that just return a "handle" to the DLL that is already loaded (which
would enable me to accomplish the above) - or will it load a new
instance?

Thanks
Tim
 
C

Chris Uppal

Tim said:
Having created a JVM from C++ using the Invocation interface, how can I
call back from the Java to my C++ code?

There are only three ways to call from Java to C++ via JNI.

One is to use normal JNI code (as widely documented). I doubt if that's what
you are looking for here.

Second is to use the RegisterNatives() function which will allow you to set (or
change if you wish) the function associated with any "native" method.

Last is to represent arbitrary C++ function pointers as int-s (or long-s) in
Java space. Pass them around as much as you wish in Java, but when you want to
invoke the functions, you have to pass the int (or long) over JNI to your C++
code. That code would cast the bit-pattern to a function pointer, and then
call it. Obviously handling arguments and return values will require a bit more
work. You can get a similar effect (more type-safe but also more work for less
flexibility) by building an array of function pointers in C++ and passing
indexes into that array to Java instead of casting function pointers to ints.

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top