Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2004

Tip: Looking for answers? Try searching our database.

Return jbyte to a C function (JNI)

Thread view: 
Ann - 17 Nov 2004 23:42 GMT
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
Gordon Beaton - 18 Nov 2004 07:39 GMT
> 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

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.