Solved

JNI - Passing object from Java to C++

Posted on 1998-05-12
6
313 Views
Last Modified: 2012-08-13
I'm currently trying to integrate some C++ code into a Java application.
I know, using JNI, that it is easy to invoke a C++ function from Java and pass some parameters.

Question: JNI provide some info. on how to pass basic variable type (int, string, etc...) but how
      do I pass an object and let the C++ code manipulate it ?
0
Comment
Question by:hleungtack
  • 2
  • 2
  • 2
6 Comments
 
LVL 5

Expert Comment

by:msmolyak
ID: 1220935
C++ programming using JNI is different from C programming mainly in form, the essence is the same. It simply offers somewhat cleaner interface. You can manipulate objects using C as well. Check out the tutorial at http://java.sun.com/docs/books/tutorial/native1.1/implementing/index.html

It has a separate section on C++ programming (mainly it describes how to integrate C and Java programs).

If you have any specific questions, do not hesitate to ask.
0
 

Author Comment

by:hleungtack
ID: 1220936
I already read this tutorial... but it seems this solution is quite painful. I have ~50 classes so
I don't want to write all theses codes described in the tutorial  to access my 50 classes ....
I would like someting more "natural" ... like a direct mapping between Java class and C class
then manipulate the object in C exactly as if it was a C/C++ program.

0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1220937
I understand your concern. Trying to code 50 classes natively will indeed produce a lot of unruly code. Then may be you should not be doing what you are trying to do? Why are you using JNI on such a massive scale. JNI is designed as a patch (as anything that concerns direct translation between two languages) not as a way for mainstream Java programming.  CORBA would be much a cleaner solution (and more "natural") for bringing together the objects written in various OO languages.
0
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

 

Author Comment

by:hleungtack
ID: 1220938
The Java application I'm writing is talking CORBA on the backend. For a reason I don't have control on, the CORBA Server dosn't support IIOP and the ORB vendor provide a IDL compiler for ONLY C language.
My application has to be in Java.
I agree this is not natural at all (and ugly too). Eventually I may
come up with another solution: write my application in C++....
Thanks for your help anyway.

0
 
LVL 4

Accepted Solution

by:
evijay earned 80 total points
ID: 1220939
0
 
LVL 4

Expert Comment

by:evijay
ID: 1220940
Interfacing to Existing C and C++ Libraries


go to

http://www.developer.com/reference/library/1575211025/ch32.htm
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

746 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

11 Experts available now in Live!

Get 1:1 Help Now