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?
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.