Solved

passing java object to c through jni

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 87
eclipse shortcuts 9 45
servlet  URL Rewriting 1 28
Android tablet will not connect to internet. 4 10
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

863 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

20 Experts available now in Live!

Get 1:1 Help Now