How do I convert jstring to wchar_t *

前端 未结 10 860
闹比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:29

    Here is how I converted jstring to LPWSTR.

    const char* nativeString = env->GetStringUTFChars(javaString, 0);
    size_t size = strlen(nativeString) + 1;
    LPWSTR lpwstr = new wchar_t[size];
    size_t outSize;
    mbstowcs_s(&outSize, lpwstr, size, nativeString, size - 1);
    

提交回复
热议问题