unicode - 如何从#defined 的 ascii 字符串初始化 WCHAR 字符串。不包括 L 前缀
问题描述
在 Windows 驱动程序 C 代码中,我需要将 WCHAR 数组设置为在头文件中 #defined 的字符串。头文件指定一个 ascii 字符串。它没有为字符串指定 L 前缀。
// In the header file
#define VERS_STR "3.2.4"
// In the C file, none of the following work
WCHAR awcStr[] = LVERS_STR; // Compiler Error: Treated as one name
WCHAR awcStr[] = L VERS_STR; // Compiler Error: L is unknown
WCHAR awcStr[] = L(VERS_STR); // Compiler Error
WCHAR awcStr[] = L"3.2.4"; // Compiles and runs, but I must use #define instead
我会在#define 上调用一个转换例程,但是我找不到可以使用C 代码从Windows 驱动程序调用的转换例程。
解决方案
可能存在 WIDE 宏,但我无法轻松检查,但这个序列实现了它:
#define WIDE2(x) L##x
#define WIDE1(x) WIDE2(x)
#define WIDE(x) WIDE1(x)
由于宏的工作方式,WIDE1 将扩展您的宏,而 WIDE2 将使用连接宏运算符添加 L。只要打电话WIDE(VERS_STR)
。
推荐阅读
- prolog - 未定义的过程 DWIM 无法更正 Prolog 中的目标
- python - 使用 enumerate() 时出现“ValueError:需要超过 2 个值才能解压”
- twitter-bootstrap - dc js 选择菜单和带有引导程序的样式
- android - RxJava2 onSubscribe 和 onComplete
- mysql - 如何在 Laravel 5.2 中获取最新情况后的行号?
- go - Go 无法从字符串创建全局字节切片
- javascript - 我的单元测试配置有几个问题
- python - PyQt5 - 底图和 Matplotlib 散点图选择器
- django - Django,如何允许多个图像上传,基于类的视图,2 种形式
- c - 在 C 中每次输入后如何自动按“ENTER”键?