Solved

JNI - mapping integer pointers in vc++ through JNI

Posted on 2001-07-26
5
736 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
5 Comments
 
LVL 3

Expert Comment

by:stimpyjcat
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

772 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

11 Experts available now in Live!

Get 1:1 Help Now