You can release a hook function and remove its address from the hook list by calling WinReleaseHook with the same arguments that you used when installing the hook function, as shown in the following sample code:
BOOL EXPENTRY MyInputHook(HAB, PQMSG, USHORT); HAB hab; HMQ hmq; WinReleaseHook(hab, /* Anchor block handle */ hmq, /* Thread message queue */ HK_INPUT, /* Called by the input hook */ (PFN) MyInputHook, /* Address of input-hook function */ (HMODULE)NULL); /* Function is in appl. module */
Release all hook functions before the application ends, even though the system automatically releases them if the application does not. You also need to free the memory associated with the hook.