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

From: Gordon Beaton (not_at_for.email)
Date: 11/30/04


Date: 30 Nov 2004 09:16:27 +0100

On 29 Nov 2004 17:38:21 -0800, Alex wrote:
> 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

-- 
[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e


Relevant Pages