I'm trying to pass a java.lang.String
from Java to C++ but there seems to be a little mistake in the code encoding from java String to Windows WCHAR*.
On the Java side I have
public native void sendText(String text);
And on the C++ side
JNIEXPORT void JNICALL Java_test_sendText(JNIEnv *env, jobject o, jstring text) {
const jchar* _text = env->GetStringChars(text, FALSE);
const WCHAR* txt = (const WCHAR*)_text;
UINT32 len = (UINT32)wcslen(txt);
IDWriteTextLayout* textLayout;
DWriteFactory->CreateTextLayout(txt, len, textFormat, rect.right - x, rect.bottom - y, &textLayout);
g->DrawTextLayout(D2D1::Point2F(x, y), textLayout, currBrush);
env->ReleaseStringChars(text, _text);
}
I'm trying to send the String test string: 00:00:00 but on the C++ side I'm getting things like Àest string: 00:00:00 and Ùest string: 00:00:00. It seems like only the first character is failing to convert, I have the unicode charset selected in MSVS but I don't have a clue what's going wrong. I have searched around and other posts say a simple cast between jchar* and wchar_t* should be possible.