gpt4 book ai didi

c++ - 当我运行 C++ 代码时,总是出现 Visual Studio 错误 C2664

转载 作者:行者123 更新时间:2023-11-28 02:09:17 25 4
gpt4 key购买 nike

当我使用这段代码时

if (GetKeyNameText(Key << 16, NameBuffer, 127))
{
KeyName = NameBuffer;
GoodKeyName = true;
}

出现以下错误

C2664 'int GetKeyNameTextW(LONG,LPWSTR,int)': cannot convert argument 2 from 'char [128]' to 'LPWSTR'

NameBuffer 是这样说的:

Error: argument of type "char*" is incompatible with parameter of type "LPWSTR"

有什么建议吗?

最佳答案

您定义了 UNICODE,这意味着您的所有函数以及 TCHARLPTSTR 都默认为 wide 字符(wchar_t).

这意味着您不能在没有特别注意的情况下使用窄字符字符串(使用 char)。

有一个简单的解决方案,那就是显式调用函数的窄字符版本:GetKeyNameTextA

另一种解决方案是停止使用 char 并更改为 TCHAR 和相关类型,并对字符串文字使用 T 宏。

您可能想阅读有关 UNICODE in the Windows API 的更多信息.

关于c++ - 当我运行 C++ 代码时,总是出现 Visual Studio 错误 C2664,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36333429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com