Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sending and retriveing struct using JNI

Posted on 1997-10-08
2
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 270 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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