> I have a C++ class with its own instance variables. In Java, I call
> a method to create a new object and initialize all the variables.
> Now the issue I am facing is calling the next method on the same
> object created.
There are a few ways to do this.
For example, store the C++ object in any suitable native structure
such as an array or hashtable, and store the index or key (as
appropriate) in the corresponding Java object. Include the index when
you invoke any of your native methods, so the correct object can be
looked up.
Or simply return the address of the C++ object as a long that you
store in the corresponding Java object. In your native methods, cast
back to the correct type before calling the C++ object method.
Finally, have a look at "peer classes" here:
http://java.sun.com/docs/books/jni/html/jniTOC.html
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
codesrik@yahoo.com - 02 Jan 2007 15:37 GMT
> Or simply return the address of the C++ object as a long that you
> store in the corresponding Java object. In your native methods, cast
> back to the correct type before calling the C++ object method.
Thnx Gordon. I will try implementing the "long" solution and see how it
goes.