• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing objects w/ JNI

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic