Solved

JNI - Passing object from Java to C++

Posted on 1998-05-12
6
336 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

617 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