mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Small changes in modules searching algorithm, fix resource leak.
This commit is contained in:
parent
a523b8e3d7
commit
9232cfbdc7
|
@ -108,6 +108,7 @@ BOOL HookAPI(LPCSTR szImportModule, LPCSTR szFunc, PROC paHookFuncs, PROC* paOri
|
|||
HANDLE hSnapshot;
|
||||
MODULEENTRY32 me;
|
||||
BOOL bOk;
|
||||
DWORD err;
|
||||
|
||||
ZeroMemory(&me,sizeof(me));
|
||||
me.dwSize=sizeof(me);
|
||||
|
@ -116,12 +117,20 @@ BOOL HookAPI(LPCSTR szImportModule, LPCSTR szFunc, PROC paHookFuncs, PROC* paOri
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
do {
|
||||
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,0);
|
||||
if(hSnapshot != INVALID_HANDLE_VALUE) break;
|
||||
err = GetLastError();
|
||||
if(err == ERROR_BAD_LENGTH) Sleep(100);
|
||||
} while(err == ERROR_BAD_LENGTH);
|
||||
|
||||
if(hSnapshot == INVALID_HANDLE_VALUE) return FALSE;
|
||||
|
||||
bOk = Module32First(hSnapshot,&me);
|
||||
while (bOk) {
|
||||
HookImportFunction(me.hModule, szImportModule, szFunc, paHookFuncs, paOrigFuncs);
|
||||
bOk = Module32Next(hSnapshot,&me);
|
||||
}
|
||||
CloseHandle(hSnapshot);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue