Solved

JNI - mapping integer pointers in vc++ through JNI

Posted on 2001-07-26
5
743 Views
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.
Jeganathan
0
Comment
Question by:Jeganathan
[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
5 Comments
 
LVL 3

Expert Comment

by:stimpyjcat
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.

0
 

Author Comment

by:Jeganathan
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.  





}
0
 
LVL 3

Accepted Solution

by:
stimpyjcat earned 50 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.
0
 

Expert Comment

by:CleanupPing
ID: 9061947
Jeganathan:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
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.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java imports not found 4 71
Java syntax, or is it Selenium 6 61
Html Table Looping (part 2) 5 41
dao vs facade design patterns 2 69
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 post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

734 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