JNI wchar_t problem (unix platforms)
843829Mar 26 2008 — edited Sep 1 2009Hi all,
i have such kind of broblem on unix platforms. I have unicode string in JNI and when i create jstring and return it to java the string is not completed. So,
/////////////////////////////////////////////////
wchar_t name[50] = L"Ob als Sch�ler";
jstring objectName = NULL;
len = wcslen(name);
objectName = (*env)->NewString(env, name, len);
return objectName;
////////////////////////////////////////////////
I receive in Java "Ob als". I receive warning when compile the c code, theat argument #2 is not compatible with prototype. This happened because the second parameter is unsigned short, and wchar_t, which i passed, is four bytes. How can i fix this problem with wide char string? Is it a good idea to convert wchar_t string to char string and after that to create NewStringUTF? I noticed that when the len is twice bigger i.e. len = 2*wcslen(name) the string which is created is full. Is it correct to use this function with twice more length?
Thanks,
Valentin