Call native method from java after invocation.

I've successfully loaded a jvm and instantiated a java class which my native code calls into nicely. I now have a need to allow the java class to call back into a native side method (after it has been invoked, etc. from the native side of course).

Could anyone point me to how to do this so that the java class is calling into the correct instance of the native code that invoked it? i.e. since the native code can create multiple instances of the java class (and it does), I need to make sure any call backs go to the proper instance of the native class that instantiated it.

I hope I have explained this properly... If I should clarify anything, please let me know.

PD

[697 byte] By [powerdroida] at [2007-11-27 5:30:02]
# 1

> I've successfully loaded a jvm and instantiated a

> java class which my native code calls into nicely. I

> now have a need to allow the java class to call back

> into a native side method (after it has been invoked,

> etc. from the native side of course).

>

> Could anyone point me to how to do this so that the

> java class is calling into the correct instance of

> the native code that invoked it? i.e. since the

> native code can create multiple instances of the java

> class (and it does), I need to make sure any call

> backs go to the proper instance of the native class

> that instantiated it.

>

> I hope I have explained this properly... If I should

> clarify anything, please let me know.

class CppPeer {

private long pointer;

CppPeer(long pointer) {

this.pointer = pointer;

}

}

When you create the Java object from native code, pass the pointer to the Java side where it can be stored as an int (or long). When Java calls back into the native side, pass the pointer variable along. The native code can cast the long back to the proper pointer type and then you can use that pointer.

Jim S.

Niceguy1a at 2007-7-12 14:53:43 > top of Java-index,Java HotSpot Virtual Machine,Specifications...