HMODULE GetModule(DWORD processId, const std::wstring& moduleName) {
HMODULE hModule = NULL;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId);
if (hSnapshot) {
MODULEENTRY32 me;
me.dwSize = sizeof(me);
if (Module32First(hSnapshot, &me)) {
do {
if (me.th32ProcessID == processId && me.szModule == moduleName) {
hModule = me.hModule;
break;
}
} while (Module32Next(hSnapshot, &me));
}
CloseHandle(hSnapshot);
}
return hModule;
}