更新时间:2023-11-11 20:59:28
对于这个特定案例,修复非常简单:
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);
也就是说,始终使用 Unicode 字符串.一般来说,在 Windows 上编程时,使用 wchar_t
和 UTF-16 可能是最简单的.当然,这取决于您必须与其他系统进行多少交互.
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.
对于一般情况,如果您有一个 ASCII(或 char *
)字符串,请使用 WideCharToMultiByte 用于一般情况,或者 mbstowcs
如@Matthew 指出的更简单的情况(mbstowcs
如果字符串在当前 C 语言环境中有效).
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).