Solved

sending and retriveing struct using JNI

Posted on 1997-10-08
2
308 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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
computer science syllabus 3 52
json example 39 110
create a gui in perl 3 42
Where to store the queries for modification of table 4 24
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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

8 Experts available now in Live!

Get 1:1 Help Now