Solved

sending and retriveing struct using JNI

Posted on 1997-10-08
2
309 Views
Last Modified: 2012-05-04
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
Comment
Question by:praveen090397
  • 2
2 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1228178
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
 
LVL 6

Accepted Solution

by:
jpk041897 earned 90 total points
ID: 1228179
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now