C++ visual studio error C2664

≡放荡痞女 提交于 2019-12-12 04:16:14

问题


When I use this code

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

I get the following error

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

The NameBuffer says this:

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

Any tips?


回答1:


You have UNICODE defined, which means all your functions and TCHAR and LPTSTR are defaulting to wide characters (wchar_t).

That means you can't use a narrow-character string (using char) without special care.

There is an easy solution, and that's to explicitly call the narrow-character version of the function: GetKeyNameTextA.

Another solution is to stop using char and change to TCHAR and related types, and use the T macro for string literals.

You might want to read more about UNICODE in the Windows API.



来源:https://stackoverflow.com/questions/36333429/c-visual-studio-error-c2664

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!