Unloading DLL from all processes after unhooking global CBT hook

前端 未结 2 819
南笙
南笙 2021-01-03 06:44

How do you properly unload a DLL from all processes when the system-wide hook that loaded them gets unloaded?

From MSDN:

You can release a gl

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 07:26

    Hook dll are unloaded in their message loop. Forcing them to pass in the message loop help to unload them.

    Add this after your UnhookWindowsHookEx to force all message loops to wake up :

    DWORD dwResult;
    SendMessageTimeout(HWND_BROADCAST, WM_NULL, 0, 0, SMTO_ABORTIFHUNG|SMTO_NOTIMEOUTIFNOTHUNG, 1000, &dwResult);
    

    However I still have the issue from time to time. I don't know where it's coming from. I suppose a locked process could prevent the dll to unload, but I have no proof of that.

提交回复
热议问题