Invocation JVM and JNI library communication

How do I communicate between my application that creates a VM, and the JNI libraries (with native functions) loaded by classes within the invoked VM?
[170 byte] By [hlindqvi] at [2007-9-26 8:29:08]
# 1
-Global variables-Primitives passed as arguments-Primitives as attributes in a class-C/C++ pointers passed as arguments or as class attributes using a java long to hold it.-Function callbacks.
jschell at 2007-7-1 19:08:04 > top of Java-index,Core,Core APIs...
# 2

> -Global variables

I doubt global variables inside the C app can be accessed from JNI native methods.

> -Primitives passed as arguments

Sure, but there is an whole API in C I wan't to make available in Java.

> -Primitives as attributes in a class

Explain? Attributes in class?

> -C/C++ pointers passed as arguments or as class

> attributes using a java long to hold it.

Yes, this is probably the way!

> -Function callbacks.

Explain?

Application layout:

C application <-> [ invoked JVM with Java class ] <-> JNI native library

I wan't to share native info between:

C application <-> JNI native library

hlindqvi at 2007-7-1 19:08:04 > top of Java-index,Core,Core APIs...
# 3

>> -Global variables

>

>I doubt global variables inside the C app can be >accessed from JNI native methods.

Whoops! Correct.

>> -Primitives passed as arguments

>

>Sure, but there is an whole API in C I wan't to make

>available in Java.

>

>> -Primitives as attributes in a class

>

>Explain? Attributes in class?

Basically the same as the previous one. So probably no more useful.

>> -C/C++ pointers passed as arguments or as class

>> attributes using a java long to hold it.

>

>Yes, this is probably the way!

You will probably find this is best.

> -Function callbacks.

Presumably you control the code base for both sides of this. A JNI shared library can have normal shared library method calls in it. So use normal shared library protocols to access it. (I haven't tried it so there might be some interesting problems with initially resolving the thunks or there might not.)

jschell at 2007-7-1 19:08:04 > top of Java-index,Core,Core APIs...
# 4

You can't use C pointers, at least under Windows, since the C app. and the JNI-invoked DLL are separate processes and hence have separate memory spaces. You can send messages that pass primitives or use the WM_COPYMEMORY message to send objects. You can also use DDE or COM although they may be too "heavyweight".

Regards.

achalk at 2007-7-1 19:08:04 > top of Java-index,Core,Core APIs...
# 5

>You can't use C pointers, at least under Windows, since the C app. and the JNI-invoked DLL are separate processes...

uh? No, that isn't correct.

Java and the dlls it loads( or any application that loads dlls) are not seperate processes.

And pointers can be used. I have certainly done so in the past.

jschell at 2007-7-1 19:08:04 > top of Java-index,Core,Core APIs...