Solved

JNI - Passing object from Java to C++

Posted on 1998-05-12
6
316 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reasons why a "inside Menu" would not appear for a web server 6 56
Hibernate Not Rolling Back When something fails in a stored procedure 2 50
Java and GPO 11 68
Java Loop 6 48
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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

912 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

21 Experts available now in Live!

Get 1:1 Help Now