uintptr_t gameModule = (uintptr_t)GetModuleHandle("client.dll");
Severity Code Description Project File Line Suppression State Error C2664 'HMODULE GetModuleHandleW(LPCWSTR)': cannot convert argument 1 from 'const char [11]' to 'LPCWSTR'
uintptr_t gameModule = (uintptr_t)GetModuleHandle("client.dll");
Severity Code Description Project File Line Suppression State Error C2664 'HMODULE GetModuleHandleW(LPCWSTR)': cannot convert argument 1 from 'const char [11]' to 'LPCWSTR'
uintptr_t gameModule = (uintptr_t)GetModuleHandle("client.dll");
HMODULE GetModuleHandleW(LPCWSTR)': cannot convert argument 1 from 'const char [11]' to 'LPCWSTR'
"client.dll"
is a char
string (const char [11]
).
According to the Windows API TCHAR model, GetModuleHandle
is a preprocessor macro which is expanded to GetModuleHandleW
in Unicode builds (the default build mode for Visual Studio C++ projects since VS 2005).
GetModuleHandleW
requires a LPCWSTR
string parameter, i.e. a const wchar_t*
, which is a wchar-t
string.
So, you have a mismatch in your GetModuleHandle
call, as you passed a char
string, but GetModuleHandle
(which is expanded to GetModuleHandleW
) requires a wchar_t
string (LPCWSTR
).
You can fix this error passing L"client.dll"
instead of "client.dll"
; in fact, L"client.dll"
(note the L prefix) is a wchar_t
string:
// Pass L"client.dll" instead of "client.dll"
uintptr_t gameModule = (uintptr_t)GetModuleHandle(L"client.dll");
Another option would be explicitly invoking the "ANSI" function GetModuleHandleA
:
// Explicitly call GetModuleHandleA
uintptr_t gameModule = (uintptr_t)GetModuleHandleA("client.dll");
but I would stick with Unicode APIs.
You could even totally embrace the TCHAR model, and decorate your string literal with _T()
or TEXT()
, e.g.:
uintptr_t gameModule = (uintptr_t)GetModuleHandle(_T("client.dll"));
That would work in both ANSI and UNICODE builds.