Hanzki
Hanzki

Reputation: 11

When I run the C++ code, I always get Visual Studio error C2664

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?

Upvotes: 1

Views: 5707

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409136

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.

Upvotes: 2

Related Questions