JNI: Passing array of objects from C++ to Java

A

Alex

From C++ to Java using JNI
I need to pass an array of orbitrary number of objetcts
that consists of a string and a float.


All suggestions are really appriciated!
Thnaks
 
G

Gordon Beaton

From C++ to Java using JNI
I need to pass an array of orbitrary number of objetcts
that consists of a string and a float.

Please don't multipost. Followup set.

Have you used JNI at all?

What *specifically* are you having problems with?

- Get the class descriptor with FindClass() or GetObjectClass().

- Create an empty array of the appropriate size with NewObjectArray().

- Use SetObjectArrayElement() to populate the array with instances of
your class.

- To call the Java method, look up the method in the class with
GetMethodId() or GetStaticMethodId(), then call it using the
appropriate CallXXXMethod() function. Pass your array as an
argument.

The JNI tutorial is here (the section on invocation is dated but the
rest is still valid):

http://java.sun.com/docs/books/tutorial/native1.1/index.html

In particular, look at these sections (but look at the rest too):

http://java.sun.com/docs/books/tutorial/native1.1/implementing/array.html
http://java.sun.com/docs/books/tutorial/native1.1/implementing/method.html

The complete JNI specification is here:

http://java.sun.com/j2se/1.5.0/docs/guide/jni/index.html

/gordon
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top