For this specific case, the fix is quite simple:
wchar_t szBuff[64];
swprintf(szBuff, L"%p", m_hWnd);
MessageBox(NULL, szBuff, L"Test print handler", MB_OK);
That is, use Unicode strings throughout. In general, when programming on Windows, using wchar_t
and UTF-16 is probably the simplest. It depends on how much interaction with other systems you have to do, of course.
For the general case, if you've got an ASCII (or char *
) string, use either WideCharToMultiByte for the general case, or mbstowcs
as @Matthew points out for simpler cases (mbstowcs
works if the string is in the current C locale).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…