Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Passing (byref) String from Java to C++ via JNI

843829Oct 21 2002 — edited Oct 23 2002
I wish to pass a string to a C++ Dll as a parameter in a function. The problem is that I don't know howto receive back the data after it is filled in the C++ dll. I am trying to do what is called passing parameters by reference.

Java Code:
public class ABKeyBoard {
public native long leerBanda(int pista, String datos);
public static void main(String[] args) {
String datos=new String();
System.loadLibrary("ABKeyBoard");
new ABKeyBoard().leerBanda(1,datos);
System.out.println(datos); //the content of datos here is empty.
}

C++ Code:
Java_ABKeyBoard_leerBanda(JNIEnv *env, jobject obj,jint pista, jstring datos)
{
char buffer[2024];

memset(buffer, 0x00, sizeof(buffer));
strcpy(buffer, "xxxx");
datos = env->NewStringUTF(buffer);
return;
}

Thanks for your help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 20 2002
Added on Oct 21 2002
3 comments
971 views