How unintall hook with out freezing

Nov 3, 2008 at 3:15 AM
What is the proper way to uninstall a hook in a unmanaged DLL?

I currently call:

inside of DllMain for the DLL_PROCESS_DETACH event but the injected program then freezes.

Nov 3, 2008 at 4:26 AM
You have to arrange for LhUninstallAllHooks and LhWaitForPendingRemovals to be called before the reference count on your library decreases to 0 (causing DllMain to be called).

In DllMain's DLL_PROCESS_DETACH, you can check that all of the hooks have been removed and log an error to a file for debugging purposes, but you can't actually free up resources.  There's a good description of why doing much of anything in DllMain leads to deadlocks over at The Old New Thing.