JNI - mapping integer pointers in vc++ through JNI

Posted on 2001-07-26
Medium Priority
Last Modified: 2013-11-23
Hi! Anyone,
I have a native function defined in VC++ which is returning int*.  Actually I would like to map this int * with JNI.  Do anyone throw some light on this.  

Thanks in advance.
Question by:Jeganathan
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

Expert Comment

ID: 6322669
If you mean you simply want to store it, you can stuff it into int or long member data using JNI member access methods.

Otherwise you'll need to clarify what you mean by mapping the integer pointer.


Author Comment

ID: 6326141
My VC++ native function looks something like this

JNIEXPORT int* JNICALL readSrl(JNIEnv *env, jobject obj)
  int* srl = new int[8];

  byte [] b = {1,2,3,4,5,6,7,8};

  for(int i=0; i<8; ++i)
    srl[i] = b[i];

 return srl;

Can anyone suggest the method signature that should be declared in Java using this native function.  


Accepted Solution

stimpyjcat earned 200 total points
ID: 6326438
So it's not that you want to store a pointer to an integer, you want to store an array of integers.

To see the proper signature for returning an array of integers, do the following:

1) compile a simple java function which returns the type you're interested in (int[]), e.g.

public class Serial {
int[] readSrl() {
     return new int[] { 1,2,3,4,5,6,7,8 };

2) run javap to get the signature

javap -s Serial

It might be preferable to convert the serial to a string, since it's far easier to construct a jstring from a character array than to construct an array of jints and populate it.  If you're only interested in the unique pattern of bits, that might be preferable.  If you're interested in the individual integers, though, you should construct a java array of integers instead.

There are array copy functions in JNI which can make this a little easier; see the JNI tutorial at java.sun.com.

Expert Comment

ID: 9061947
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
LVL 14

Expert Comment

ID: 9208320
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

[points to stimpyjcat]

Please leave any comments here within the next seven days.
EE Cleanup Volunteer
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 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