0

I've got a class that I'd like to pass between C++ and an Android Project.

The Class:

public class SomeData {
    public SomeData ( byte[] data )
    {
        m_data = data;
    }

    public byte[] getData ()
    {
        return m_data;
    }

    public byte[] m_data;
... some other fields ...

}

I would like to pass it to a C++ function (using JNI interface of course) and then be able to retrieve it.

i.e - something like

public static native SomeData  getData();

Where the C++ should be able to create that class and pass it back.

How can this be done?

Many Thanks

Roman
  • 4,443
  • 14
  • 56
  • 81
  • IMO It is a lot for question and, in a way, it should be off topic. On the Sun's website you should be able to find the JNI reference book in pdf – Blackbelt Mar 14 '13 at 12:38
  • Is it so complicated to pass objects? – Roman Mar 14 '13 at 12:42
  • There are two ways you can pass an object... as a simple pointer, or initialize a real object in the VM from C... Easiest solution being passing only data/bytes through JNI and initializing objects on the java side. – Shark Mar 14 '13 at 12:48
  • @Shark - would it be possible to post a link to some resource on this method? – Roman Mar 14 '13 at 12:58
  • I have a few answers on JNI... http://stackoverflow.com/questions/8532642/c-to-java-calls-pass-but-jvm-crashes-in-a-weird-unexplained-way http://stackoverflow.com/questions/12214707/properly-returning-a-hardcoded-byte-from-jni-to-java My tip to you would be to ensure lightweight clear data passage through JNI and deal with objects in Java (instancing it when the native data is retrieved) and dealing with pointers/structs in C. Once you pull into classes / objects into all of this, you need to do smartcasts... maybe i could send you some example code to illustrate. – Shark Mar 14 '13 at 13:59
  • I can't answer because this question has been closed, but we can do exactly what you want with [JavaCPP](http://code.google.com/p/javacpp/). – Samuel Audet Mar 17 '13 at 00:36

0 Answers0