Return jbyte to a C function (JNI)

A

Ann

I have a program,which reads a String from the user.

char buf[128];
const jbyte *jnistr;
jsize strsize;
jnistr = (*env)->GetStringUTFChars(env,prompt,NULL);
if(jnistr==NULL){
return;
}
strsize = (*env)->GetStringLength(env,prompt);

testBuffer(*jnistr,strsize);


After converion, it is in the varibale jnistr ,which is a const jbyte.

My confusion starts here:
How can I pass the const jbyte to a C function, so that the whole
string is accessible.

When I try to return the jnistr, and accept it as a char parameter in
the C function testBuffer(), I can only read the first letter of the
string and nothing beyond that.

Thank You,
Ann
 
G

Gordon Beaton

const jbyte *jnistr;
testBuffer(*jnistr,strsize);
When I try to return the jnistr, and accept it as a char parameter
in the C function testBuffer(), I can only read the first letter of
the string and nothing beyond that.

That's because you've passed the wrong type to testBuffer(). If jnistr
is declared as jbyte*, then *jnistr is a single jbyte, not an array of
them.

Pass it like this instead:

testBuffer(jnistr, strsize);

I suspect that testBuffer() is declared incorrectly as well, or that
you've ignored warnings from your compiler.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top