Solved

sending and retriveing struct using JNI

Posted on 1997-10-08
2
310 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 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