Wednesday, April 24, 2013

jni jnienv ReleaseStringChars example c c++ java


ReleaseStringChars


void ReleaseStringChars(JNIEnv *env, jstring string,
const jchar *chars);

Informs the VM that the native code no longer needs access to chars. The chars argument is a pointer obtained from string usingGetStringChars().
LINKAGE:
Index 166 in the JNIEnv interface function table.
PARAMETERS of ReleaseStringChars

env: the JNI interface pointer.

string: a Java string object.

chars: a pointer to a Unicode string.
Example of ReleaseStringChars
JNIEXPORT jint JNICALL Java_Myclass_showMessage (JNIEnv* env, jobject obj, jstring title, jstring message, jint type)
{
    const jchar* _title = env->GetStringChars(title, 0);
    const jchar* _message = env->GetStringChars(message, 0);
    const int result = MessageBox(NULL, (wchar_t *) _message, (wchar_t *) _title, type);
    env->ReleaseStringChars(title, _title);
    env->ReleaseStringChars(message, _message);
    return result;
}