• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

c++ call java classes

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic