title: How can I ensure that UnhookWindowsHookEx is called even upon abnormal termination?
body: <p>Unfortunately, MSDN is not clear enough with it. I'm writing a program which uses a global hook, and I'm worrying about what would happen if the program terminates abnormally (crashes, killed by user, etc).</p>
  
  <ol>
  <li><p>Does Windows automatically unhook global hooks installed by a process when the process terminates?</p></li>
  <li><p>If not, is it possible to call UnhookWindowsHookEx() in another process to release the hook? (I'm thinking of doing this in a hooked thread, if it detects that the installer process is dead.)</p></li>
  <li><p>If the answers were no and no, isn't it dangerous to leave a global hook active when the installer process is terminated? What are the standard methods of dealing with this situation?</p></li>
  <li><p>I've read in MSDN that UnhookWindowsHookEx() doesn't free the dll loaded in other processes, but it doesn't say when will the dll be freed. <a href="http://www.codeproject.com/KB/threads/winspy.aspx">This article in CodeProject</a> seems to suggest that the dll is unmapped (in the respective process) when the first message arrives at the hooked thread, so it's about right after the UnhookWindowsHookEx() call. Is it true?</p></li>
  </ol>
  
  <p>Thank you.</p>