Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How convert from jstring to wchar_t?

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to convert from jstring to wchar_t and while it appears to be working (wprintf prints it fine) it keeps crashing the JNI program with a heap print. How do i do this? Anyone have some code?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you doing the conversion? For normal character strings, you need to use, for example, the GetStringUTFChars method to get a char*, and the ReleaseStringUTFChars method to give them back. I have never tried to use wide character strings with JNI -- how are you doing it?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
How are you doing the conversion? For normal character strings, you need to use, for example, the GetStringUTFChars method to get a char*, and the ReleaseStringUTFChars method to give them back. I have never tried to use wide character strings with JNI -- how are you doing it?


1. First I convert from jstring to char*.
2. Then I convert from char* to wchar_t.

The 2nd conversion is correct because if I hardcode in the char* value (e.g. char* UserName = "Administrator" then the whole thing works properly. Using the first conversion, prints out properly, but RegConnectRegistry says it's wrong.

EDIT: I tried using GetStringUTFChars instead and while RegConnectRegistry now says it returns successfully, it's still not working or returning a proper RegEnumKeyEx to enumerate through. So something's still wrong. (Also, it now prints that out as garbled ???, so I can't compare it to what's returned in an Enum).



What am I doing wrong here?
[ September 14, 2006: Message edited by: Dan Bizman ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic