• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c++ call java classes

 
Ruilin Yang
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Andrews
Ranch Hand
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Bee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic