This drove me nuts for hours. The MessageBox function wants wide-character strings and I wanted to put variables in my strings, not just L"" constant strings. I had already been using the Unicode character set and didn't want to change a million other things in my code, so after much toiling, I've found the following code snippet to work:
int random = 42;
char message[128];
sprintf(message, "My random number: %d\n", random);
wchar_t mess[128];
mbstowcs(mess, message, 512);
MessageBox(hWnd, mess, L"Information", MB_OK);
The 512 value in mbstowcs() should be WCHAR_MAX_LENGTH but I was too lazy to find which header contains that, so I Googled and found a random value. It seems to work for me.
Friday, March 13, 2009
Subscribe to:
Post Comments (Atom)





0 comments:
Post a Comment