• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

sending and retriveing struct using JNI

My native code is written in C++ that contains many methods
that has struct as arguments and return types.
I read up the sun's java page on JNI and I am able to call
my native methods and pass strings and primitive types.
I would like to be able to send Java objects to my native methods and which in turn should be converted to struct and
passed to native methods.
Is there a way that I can use JNI to convert my java objects
to structures and pass it to my native methods and also
take the return structures from my native methods and convert them back to java object ?

any help would be greatly appreciated

thanks
0
praveen090397
Asked:
praveen090397
  • 2
1 Solution
 
jpk041897Commented:
The problem you are running into is that structs and classes are implemented internaly as pointers to memory areas, rather than primitive data types.

As it stands, your best bet would be to implement iterators over your classes/structs using RTTI type functions to obtain the primitive objects that make up your struct and transfer those.

You can then write methods in both C++ an Java that can rebuild the struct/classses on the recieving end.

Let me know if this approach is acceptable and I'll try to post more detailed info as an answer.
0
 
jpk041897Commented:
If the approach I mentioned erlier is not acceptable, then here are other alternatives:

1. Wrap your Java Structures inside a new class, any class, and implement methods to transfer your struct variables to and from this class.

Once the class has been updated with the data you require, you can then use JNI to transfer the object itself. This would cause JNI to tranfer the address of the Object, which you could then access in C++ in order to extract the information.

2.- A probably less complicated workarroun for achieving the same result would be to use a CORBA client and server, running on the same box using localhost addressing, to transfer your structs. CORBA's IDL implementation supports both struct and any data types so you could use this approach as a somwhat simple alternative.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now