'MessageBox' 功能是否默认适用于窄字符串?你不需要使用'MessageBoxW'吗?
编辑:
有几件事要检查。L"..." 字符串的编码是实现定义的。该标准没有提及 ; 字符的编码wchar_t
。确保您使用的编码与 Windows 预期的相同。(如果我没记错的话,windows 需要 UTF-16 - 但我很可能是错的)。
在 C++11 中,引入了 3 种新的文字字符串类型,它们的前缀是“u8”、“u”和“U”,分别指定 UTF-8、UTF-16 和 UTF-32。除了第 2.14.3 节中提到的内容外,C++11 仍然不保证对“L”前缀的编码做出任何保证:
A character literal that begins with the letter L, such as L’x’, is a wide-character literal. A wide-character
literal has type wchar_t.23 The value of a wide-character literal containing a single c-char has value equal
to the numerical value of the encoding of the c-char in the execution wide-character set, unless the c-char
has no representation in the execution wide-character set, in which case the value is implementation-defined.
[ Note: The type wchar_t is able to represent all members of the execution wide-character set (see 3.9.1).
—end note ]. The value of a wide-character literal containing multiple c-chars is implementation-defined.
参考§3.9.1 P5 状态:
Type wchar_t is a distinct type whose values can represent distinct codes for all members of the largest
extended character set specified among the supported locales (22.3.1). Type wchar_t shall have the same
size, signedness, and alignment requirements (3.11) as one of the other integral types, called its underlying
type. Types char16_t and char32_t denote distinct types with the same size, signedness, and alignment as
uint_least16_t and uint_least32_t, respectively, in <stdint.h>, called the underlying types.
同样,没有提到编码。Windows 可能期望与您的资源字符串使用的编码不同,因此存在差异。
您可以通过使用带有“\Uxxxxxxx”编码转义符的 L"" 字符串文字调用 MessageBox 来验证您的字符。