我在 DLL_PROCESS_DETACH 中处理了。
case DLL_PROCESS_ATTACH :
begin
hMutex := OpenMutex($1F0001, false, PChar(sDllName + '_Mutex'));
if hMutex = 0 then
begin
hMutex := CreateMutex(nil, false, PChar(sDllName +'_Mutex'));
hookID := SetWindowsHookEx(3, @LoadLibrary, HInstance, 0);
end;
nID := CreateThread(nil, 0, @ThreadProc, nil, 0, ThreadID);
end;
case DLL_PROCESS_DETACH:
begin
if nID <> 0 then
begin
FQuit := True;
WaitForSingleObject(nID, INFINITE);
end;
if hMutex <> 0 then
CloseHandle(hMutex);
end;
function ThreadProc(Info: Pointer): Integer;
stdcall;
begin
Result := 0;
while not FQuitdo
begin
......
sleep(1000);
end;
end;
只有在自己的程序里有用。
在被hook的程序里好像没有用 进入无限等待 不知道是怎么回事