The C++ side looks like this:
JNIEXPORT jint JNICALL Java_Myclass_showMessage (JNIEnv* env, jobject obj, jstring title, jstring message, jint type)
{
const char* _title = env->GetStringUTFChars(title, 0);
const char* _message = env->GetStringUTFChars(message, 0);
const int result = MessageBox(NULL, (LPCTSTR) _message, (LPCTSTR) _title, type);
env->ReleaseStringUTFChars(title, _title);
env->ReleaseStringUTFChars(message, _message);
return result;
}
And java side:
int result = showMessage("caption", "Hello!", 0);
However when i call the exported function from java this is what i get:
http://i54.tinypic.com/wu5hs0.png
Any idea what could cause this?
Use MessageBoxA – MessageBox autoselects the wide or mbcs version based on your projects Unicode/MBCS setting.
If you need to cast to LPCTSTR that’s an indication something’s wrong.
Alternatively, use GetStringChars and MessageBoxW, in this case you may need to cast depending on what jchar is defined as.
EDIT: Sample code
The cast works in this case since wchar_t happen to be 16 bits wide, same as jchar.