Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JNI - Passing object from Java to C++

Posted on 1998-05-12
6
Medium Priority
?
354 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
[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
  • 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

721 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