Solved

passing java object to c through jni

Posted on 2016-10-27
2
56 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
dpearson earned 500 total points
ID: 41866314
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 14

Expert Comment

by:frankhelk
ID: 41903911
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

688 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