www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Invalid conversion from utf8 string when it is in variable

reply "rsk82" <rsk82 live.com> writes:
The effect here is that the message text is correct in greek 
letters but message title is all empty boxes, sometimes with 
other texts there are chinese chars.

string msg= "ένα μήνυμα";
MessageBoxW(null, "ένα μήνυμα", cast(wchar*)msg.toStringz, 
MB_ICONERROR);

http://s9.postimage.org/66e84i80r/msgbox.png
Jan 28 2013
parent "John Chapman" <johnch_atms hotmail.com> writes:
On Monday, 28 January 2013 at 11:17:02 UTC, rsk82 wrote:
 The effect here is that the message text is correct in greek 
 letters but message title is all empty boxes, sometimes with 
 other texts there are chinese chars.

 string msg= "ένα μήνυμα";
 MessageBoxW(null, "ένα μήνυμα", cast(wchar*)msg.toStringz, 
 MB_ICONERROR);

 http://s9.postimage.org/66e84i80r/msgbox.png
You're casting UTF-8 (char*) to UTF-16 (wchar*). Instead, use the conversions in std.utf - ie, msg.toUTF16z().
Jan 28 2013