• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing objects w/ JNI  RSS feed

 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if it was possible to pass objects from C++ back to Java using JNI if not, what about structs?
In the end what I want to do is pass an array of these objects back to Java and copy thier values into a Java object that will then be used to insert data into a DB.
 
Nathan Washor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is possible to do what you're asking. What you'll want to do is make some Java objects that match your C++ objects. If the C++ Objects contain other Objects, you'll need to make identical Java objects of those types too. Then you need to write some methods in C++ which instantiate new Java Objects (the one's you are moving your data into) and copy the C++ Objects data into the Java Object's fields. Then the methods return these instantiated Java Objects to the Java Virtual Machine. This is all assuming you start execution in Java, and then call a C++ library to return the objects from the native side. If you are going the other way (start execution in C++ and send java objects to the JVM, and have the JVM do it's stuff with the data) then this needs to be altered a little. I always start in Java, so look around for some help on how to do it the other way. Should be very similar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!