aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes c++ call java classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "c++ call java classes" Watch "c++ call java classes" New topic
Author

c++ call java classes

Ruilin Yang
Ranch Hand

Joined: Jan 06, 2002
Posts: 150
I need to call Java classes in my c++ code. I do not know how to implement such a call.
Please help.
Thanks
Ruilin
Jeremy Wilson
Ranch Hand

Joined: Feb 18, 2003
Posts: 166
You will need to use the JNI Java Native interface API. Quick explanation is you run javah (pretty sure that is what is is) to generate a .h file to include with C++ code. At this point you need to create a C++ native dll which will wrap those java functions. In the C++ code you will then interface with the .dll Refer to JNI documentation for specifics.


Jeremy Wilson
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

I need to call Java classes in my c++ code.

I believe Ruilin is trying to do the opposite; call a Java class from C++, which I believe is impossible.

Barry
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Nope Barry... the JNI goes both ways...

Take a look in the JNI Tutorial on Sun's website. It shows how to launch a JVM inside a C/C++ program and interact with it.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Dave Bee
Greenhorn

Joined: Jan 02, 2004
Posts: 3
I am trying to access java classes from Objective C/C++. My attempts to create the JVM using functions found in the jni.h file have so far returned error codes < 0 which indicates an error. I have had a -3 error which I think means a version problem. I think that has been fixed, but now I have the -1 error and have found no corresponding meaning for that one. One other question I have is: can I create an object in Objective C based on a java class and invoke all the functions in that class? AND if I create more than one object in Objective C that is based on a java class how will I be able to keep the instances straight in the JVM? (if that makes any sense). If one if these objects created in ObjC based on a java class either has a return value of "object" or needs to pass a parameter that is of type "object"(non primitive data type) how is that handled?
Am I making this harder than it is? if so please enlighten me.
Thanks in advance
DB


Conformity is the jailer of freedom and the enemy of growth.<p>JFK
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: c++ call java classes
 
Similar Threads
call java classes from within c++ code
JNI - CPointer, CMalloc, CFunction
c++ call java classes
Stubs and Mock Object
Calling other Classes from main class