What encoding Win32 API functions expect?

前端 未结 2 1214
失恋的感觉
失恋的感觉 2021-01-18 17:50

For example, MessageBox function has LPCTSTR typed argument for text and caption, which is a pointer to char or pointer to wchar when _UNICODE or _MBCS are defined, respecti

相关标签:
2条回答
  • 2021-01-18 18:03

    The ...A functions are obsolete and only wrap the ...W functions. The former were required for compatibility with Windows 9x, but since that is not used any more, you should avoid them at any costs and use the ...W functions exclusively. They require UTF-16 strings, the only native Windows encoding. All modern Windows versions should support non-BMP characters quite well (if there is a font that has these characters, of course).

    0 讨论(0)
  • 2021-01-18 18:12

    There are normally two different implementations of each function:

    • MessageBoxA, which accepts ANSI strings
    • MessageBoxW, which accepts Unicode strings

    Here, 'ANSI' means the multi-byte code page currently assigned to the process. This varies according to the user's preferences and locale setting, although Win32 API functions such as WideCharToMultiByte can be counted on to do the right conversion, and the GetACP function will tell you the code page in use. MSDN explains the ANSI code page and how it interacts with Unicode.

    'Unicode' generally means UCS-2; that is, support for characters above 0xFFFF isn't consistent. I haven't tried this, but UI functions such as MessageBox in recent versions (> Windows 2000) should support characters outside the BMP.

    0 讨论(0)
提交回复
热议问题