Solved

passing java object to c through jni

Posted on 2016-10-27
2
35 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This is an explanation of a simple data model to help parse a JSON feed
The viewer will learn how to implement Singleton Design Pattern in Java.
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.

813 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