Passing (byref) String from Java to C++ via JNI
843829Oct 21 2002 — edited Oct 23 2002I 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.