I am new to c++ and this code always returns NULL even though i know the file exists:
HMODULE hModule = GetModuleHandle(TEXT("C:\\Users\\Steve\\Desktop\\stub.exe"));
Interestingly, if i copy stub.exe to C:\Windows\system32, it finds the module with this code:
HMODULE hModule = GetModuleHandle(TEXT("stub.exe"));
Am i missing something incredibly basic?
You can only call
GetModuleHandle(L"C:\\Users\\Steve\\Desktop\\stub.exe");when you’re runningC:\Users\Steve\Desktop\stub.exe.But in general, you don’t call
GetModuleHandlefor your EXE name. Since there’s only one EXE per process, you just callGetModuleHandle(0).