C++ JNI jobject conversion

T

Tim Wong

I have a java method setup where it will be accessed in C++ via JNI.
The process is as follows:

1) C++ function getObject(...) is called.

2) getObject(...) uses JNI to access a java class method
getJObject(...).

3) getJObject(...) will do some calculations, save them to a complex
object. This object is downcasted to the class "Object" and returned.

4) C++ function getObject(...) get's back a <jbyteArray> from the JNI
call and casts this to a jobject.

My question is...what can methods can I perfrom on this jobject. What
fields can I access? I'm trying to convert it into an already existing
C++ class, but am unsure on what i can do.


Help Please!

Tim
 
V

Victor Bazarov

Tim said:
I have a java method setup where it will be accessed in C++ via JNI.

....which is completely off-topic here...
The process is as follows:

1) C++ function getObject(...) is called.

2) getObject(...) uses JNI to access a java class method
getJObject(...).

3) getJObject(...) will do some calculations, save them to a complex
object. This object is downcasted to the class "Object" and returned.

4) C++ function getObject(...) get's back a <jbyteArray> from the JNI
call and casts this to a jobject.

I can see everything relates to Java and the way _it_ is set to interact
with C++, but C++ knows not how to interact with Java.
My question is...what can methods can I perfrom on this jobject.

What can methods? What's a "can method"?
What
fields can I access?

Fields? You mean, members? Public members from any non-member and
non-friend functions, public and protected members from an object on
the same class hierarchy and any members from a member or a friend.
I'm trying to convert it into an already existing
C++ class, but am unsure on what i can do.

Do what you need, and if you encounter errors, post again. To the
Java newsgroup. Unless your question is about C++ only, then your
post should contain no mention of Java whatsoever.

V
 
J

Jesper Madsen

You can decode your jbyteArray and create a java object from it, but there
are no methods mystically attach to it,
just by saving a stream of data... So.. you should be able to cast it to an
array of bytes in java, and access methods of a java array, but that is
about it there is not much else possible.

What you want is to have a C++ wrapper that can be created from a JByteArray
and something else, and a Java class that can be created from an array of
bytes, and from something else... What you are doing by creating a
jbytearray, is something like streaming an object. But you would need to
create your own streaming operators/functions in both java an C++, so they
would know what byte[X] of the byte stream is.

Jesper
 
T

Tim Wong

Sorry,

I figured I was in the right news group because it was a C++ coding
question.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top