How do I convert jstring to wchar_t *

前端 未结 10 881
闹比i
闹比i 2020-12-01 14:48

Let\'s say that on the C++ side my function takes a variable of type jstring named myString. I can convert it to an ANSI string as follows:

10条回答
  •  天涯浪人
    2020-12-01 15:25

    Rather simple. But do not forget to free the memory by ReleaseStringChars

    JNIEXPORT jboolean JNICALL Java_TestClass_test(JNIEnv * env, jobject, jstring string)
    {
        const wchar_t * utf16 = (wchar_t *)env->GetStringChars(string, NULL);
        ...
        env->ReleaseStringChars(string, utf16);
    }
    

提交回复
热议问题