Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

passing java object to c through jni

Posted on 2016-10-27
2
Medium Priority
?
77 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 28

Accepted Solution

by:
dpearson earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
Suggested Courses

604 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