D2 string conversion

Jarrett Billingsley jarrett.billingsley at gmail.com
Sat May 9 08:33:14 PDT 2009


On Sat, May 9, 2009 at 11:01 AM, Sam Hu <samhudotsamhu at gmail.com> wrote:
> Hello,
>
> In D2 I tried to write a simple function which wrapps WIN32 API MessageBoxW,with which I can handle wide characters like Chinese .Below is my try:
>
> import std.string;
> import std.conv;
> import std.c.windows.windows;
>
> extern(Windows)int MessageBoxW(HWND,LPCSTR,LPCSTR,int);
> int showMessage(wchar[] msg,wchar[ ] caption=cast(wchar[])"Application",int style=MB_OK|MB_ICONINFORMATION)
> {
> return MessageBoxW(null,to!(const(char)[])(msg),to!(const(char)[])(caption),style);//try one
> return MessageBoxW(null,toStringz(to!(const(char[])(msg)),toStringz(to!(const(char)[])(caption)),style);//try two
> }
>
> But both *try one* and *try two* the above are wrong.Anyone can figure me out what's the problem and what's the right way to do would be appreciated.

Why do people always post problems and fail to post the errors they get?


More information about the Digitalmars-d-learn mailing list