Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetStringUTFChars function parameter

I'm developing Android app using jni.
And I used GetStringUTFChars function as follows

jboolean iscopy;
const char* trainfile = (env)->GetStringUTFChars(jstr, &iscopy);

But I saw another example like this

const char *inCStr = (*env)->GetStringUTFChars(env, inJNIStr, NULL);

Both works well. But I cannot find any documentation about the former grammer even that is more concise.

Where Can I find the documentation, and Is there any difference between them?

like image 438
plhn Avatar asked Sep 24 '13 05:09

plhn


1 Answers

The first example is C++ syntax and will work only in C++ programs. The second is for C programs.

The reason the two are different is that in C++ JNIEnv is a class and the functions are member functions of the env object, while in C JNIEnv is a pointer to a struct. Since what you receive as a parameter is a pointer to JNIEnv, in C you have to dereference it to access the struct members, that's why you must use *env in place of env.

This should be covered in any text on how to use JNI, but you can also find it by reading the code in the header file.

like image 74
Joni Avatar answered Sep 21 '22 12:09

Joni