mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +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);
|
||||
|
@ -115,13 +116,21 @@ BOOL HookAPI(LPCSTR szImportModule, LPCSTR szFunc, PROC paHookFuncs, PROC* paOri
|
|||
if ((szImportModule == NULL) || (szFunc == NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,0);
|
||||
|
||||
|
||||
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