如何使用Loadstring加载中文字符
How to use Loadstring to load Chinese Characters
我有一个字符串表,它定义了一个中文字符串,像这样:
STRINGTABLE
LANGAUGE 0x0C04, 0x03
BEGIN
1000 "检查环境..."
...
END
我正在尝试将该字符串加载到wchar_t缓冲区中,如下所示:
#define UNICODE
#define _UNICODE
wchar_t buffer[512];
LoadString(DLL_HANDLE, (UINT) msg_num, buffer, 512);
MessageBox(NULL, buffer, NULL, NULL);
但是,加载到缓冲区中的字符串与我的字符串表中的字符串不同。
在我的字符串表中是这样的:
检查环境...
但这是屏幕上的结果:
環境をãƒã‚§ãƒƒã‚¯ä¸...
有几件事要检查。L"…"字符串的编码由实现定义。该标准没有提到wchar_t
字符的编码;确保您使用的编码与Windows期望的相同。(如果我没记错的话,windows支持UTF-16,但我很可能记错了)。
在c++ 11中,引入了3种新的字面值字符串类型,它们的前缀是"u8", "u"answers"u",它们指定UTF-8, UTF-16 &分别utf - 32。据我所知,c++ 11仍然不保证对"L"前缀的编码,除了§2.14.3:
中提到的: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来验证您要验证的字符。
MSDN文档声明格式应该类似于IDS_CHINESESTRING L"x5e2ex52a9"
。这不是最正式的描述。我将其解释为声明unicode字符串必须以L
为前缀并使用uxxxx
转义码
相关文章:
- C++字符*缓冲区的大小
- HEX值到wchar_t字符(UTF-8)的转换
- 为什么 Serial.println(<char[]>);返回随机字符?
- 我的字符计数代码计算错误.为什么
- 字符串-C++后显示的随机字符
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 如何在C++中从字符串中分割字符
- VSCode C++调试文件名中包含中文字符的文件时插件损坏
- 嵌入式系统中未显示的中文字符(yocto,Qt 5.5.1) - 为什么Qt不使用系统字体?
- 为什么这个状态栏输出乱码的中文样字符
- 从C/C++中的.csv文件中读取中文字符
- 当给定包含中文字符的wchar_t数组时,NSString initWithBytes返回nil
- 使用WritePrinter API将中文字符打印到Line Printer
- 为什么使用中文代码页集的Windows控制台可以显示UTF-16编码的字符
- 检查Cstring是否只包含中文字符
- PHP和c++的UTF-8编码单位倒序中文字符
- 如何使用Loadstring加载中文字符
- 接收到的CSocket客户端-服务器字符串是中文字符
- 如何创建带有自定义颜色的中文和日文字符的标签
- 使用中文字符时文件名错误