How can I ensure that UnhookWindowsHookEx is called even upon abnormal termination?

  1. Yes, when a process terminates the system cleans up after it -- all handles are closed implicitly.
  2. No, it's not, and you don't need to anyway.
  3. (It's Yes and no not no and no)
  4. I don't see why there's a DLL loaded in another process involved here. (EDIT: I was originally thinking of a systemwide hook such as CBTProc -- if your hook is per-process that might be different) If you're dealing with something like the link indicated in @Hans' comment, whereby you've injected your own DLL into the target process, then you should put functionality to unload the hook inside your DLL, not tie it's correct operation to your application. (I.e. if sending the message back to your application fails inside the DLL, then your DLL should decide to unload itself) /EDIT When a DLL is loaded inside another process it's up to that process to do the freeing.