Wednesday, April 24, 2013

jni jnienv GetStringUTFChars example c c++ java


GetStringUTFChars


const char * GetStringUTFChars(JNIEnv *env, jstring string,
jboolean *isCopy);

Returns a pointer to an array of bytes representing the string in modified UTF-8 encoding. This array is valid until it is released byReleaseStringUTFChars().

If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to JNI_FALSE if no copy is made.
LINKAGE:
Index 169 in the JNIEnv interface function table.
PARAMETERS of GetStringUTFChars

env: the JNI interface pointer.

string: a Java string object.

isCopy: a pointer to a boolean.

RETURNS of GetStringUTFChars

Returns a pointer to a modified UTF-8 string, or NULL if the operation fails.
Example of GetStringUTFChars
const char* utf_string;
jboolean isCopy;
utf_string = env->GetStringUTFChars(str, &isCopy);
/* ... use string ... */
if (isCopy == JNI_TRUE) {
    env->ReleaseStringUTFChars(str, utf_string);
}