Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JNI - Passing object from Java to C++

Posted on 1998-05-12
6
Medium Priority
?
372 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 160 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

926 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