Winapi - 将 LPWCSTR 作为 LPCSTR 传递 [英] Winapi - passing LPWCSTR as LPCSTR

查看:25
本文介绍了Winapi - 将 LPWCSTR 作为 LPCSTR 传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用扩展为 CreateWindowExA 的 CreateWindowEx.该函数使用 LPCSTR 类型.我想作为第二个参数传递 MSFTEDIT_CLASS(来自 Richedit.h):

I use CreateWindowEx which expands to CreateWindowExA. That function uses LPCSTR types. I would like to pass as a second argument MSFTEDIT_CLASS (from Richedit.h):

#define MSFTEDIT_CLASS L"RICHEDIT50W"

以下转换不起作用:

(LPCSTR)MSFTEDIT_CLASS

CreateWindowEx 返回 NULL.当我以这种方式传递第二个参数时它起作用:

CreateWindowEx returns NULL. It works when I pass the second argument this way:

"RICHEDIT50W"

但我不想从标题中复制字符串.如何解决?

but I don't want to copy a string from the header. How to fix that ?

推荐答案

这里只有一个可行的解决方案:直接调用 CreateWindowExW 或通过定义 UNICODE> 预处理器符号并将通用文本映射 CreateWindowEx 扩展为 CreateWindowExW.

There is only a single, viable solution here: Call CreateWindowExW, either directly or by defining the UNICODE preprocessor symbol and have the generic-text mapping CreateWindowEx expand to CreateWindowExW.

您创建的窗口始终是 Unicode 窗口.用于与窗口通信的字符集在类注册时设置.名为 "RICHEDIT50W" 的窗口类是使用 RegisterClassExW 由系统.您无法控制这一点.

The window you are creating is a Unicode window, always. The character set used for communicating with a window is set at class registration time. The window class named "RICHEDIT50W" is registered using RegisterClassExW by the system. You don't have control over this.

由于您最终将不得不使用消息与窗口对话,因此您将需要使用消息处理函数的 Unicode 变体(GetMessageWDispatchMessageW、等等.).您不能使用 ANSI 版本,除非您对有时不会失败的应用程序感到满意.

Since you are eventually going to have to talk to the window using messages, you will need to use the Unicode variants of the message handling functions (GetMessageW, DispatchMessageW, etc.). You cannot use the ANSI versions, unless you are happy with an application, that sometimes doesn't fail.

这篇关于Winapi - 将 LPWCSTR 作为 LPCSTR 传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆