wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes How convert from jstring to wchar_t? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "How convert from jstring to wchar_t?" Watch "How convert from jstring to wchar_t?" New topic
Author

How convert from jstring to wchar_t?

Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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?


[Jess in Action][AskingGoodQuestions]
Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
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 ]
 
jQuery in Action, 2nd edition
 
subject: How convert from jstring to wchar_t?
 
Similar Threads
How to convert a JString in c++
how to convert static String return into JNI
Why RegConnectRegistry works in my exe but not via JNI?
Why isn't this char to jchar working?
Using JNI interface, how to go both ways to between JObject and C++ list structure