Reputation: 5273
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?
Upvotes: 12
Views: 21440
Reputation: 111329
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.
Upvotes: 17