PassingvaluesfromnativecodetojavawithJNI
I want to pass strings from my C Program to java
code using jni.How do I do that?
Web Development
I want to pass strings from my C Program to java
code using jni.How do I do that?
by geert pante
If your java native method has a java.lang.String as input and another as output, javah compiles it to:
JNIEXPORT jstring JNICALL Java_package_ClassName_methodName
(JNIEnv* env, jclass cl, jstring input)
Jstring's are C structs that can be converted to char* using (*env)->GetStringUTFChars and back using (*env)->NewStringUTF.
{
const char* str_in;
char* str_out;
jstring ret;
str_in = (*env)->GetStringUTFChars(env, input, NULL);
/*do something with str_in and str_out*/
ret = (*env)->NewStringUTF(env, str_out);
return ret;
}
See:
http://java.sun.com/docs/books/tutorial/native1.1/implementing/string.html
Greetings, Geert.
by sankar_2209
by sankar_2209
This discussion is closed to new replies.
Sort by Trending