Solved

passing java object to c through jni

Posted on 2016-10-27
2
18 Views
Last Modified: 2016-11-28
public class DemoStructurepass {
public int a;
public int b;
public int c;
public int d;
}
public class MainActivity extends Activity {
test clsObj ;
DemoStructurepass dss;
long iS;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

dss = new DemoStructurepass();
clsObj = new test();
iS = clsObj.functionAddcheck(dss);
// public native long functionAddcheck(DemoStructurepass dss);
}
}

Now I need to access the DemoStructurepass structure in JNI(C)
0
Comment
Question by:rr rrrrrr
2 Comments
 
LVL 26

Accepted Solution

by:
dpearson earned 500 total points
Comment Utility
JNI is a tricky thing to deal with.

I'd suggest taking an existing tutorial (e.g. http://www.ibm.com/developerworks/java/tutorials/j-jni/j-jni.html), going through all of the steps in that tutorial to make sure you have it all working.

Then modify the tutorial code to match your actual Java code.

If you're going to be writing a lot of JNI code (not just passing one object around), I'd strongly suggest looking at a toolkit like SWIG (http://www.swig.org/) which is designed to help write wrappers in various languages to go around C/C++ code.  So for this approach, you'd write the C++ code first and then generate a wrapper to access it from Java (and then hook your actual Java code to that wrapper).

Good luck!

Doug
0
 
LVL 13

Expert Comment

by:frankhelk
Comment Utility
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: dpearson (https:#a41866314)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
If your app took Google’s lash recently, here are the 5 most likely reasons.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now