title: Detect when a Module (DLL) is unloaded
body: <p>Is there a way to progammatically detect when a module - specifically a DLL - has been unloaded from a process?</p>
  
  <p>I don't have the DLL source, so I can't change it's DLL entry point. Nor can I poll if the DLL is currently loaded because the DLL may be unloaded and then reloaded between polling.</p>
  
  <p><strong>RESULTS</strong>:</p>
  
  <p>I ended up using jimharks solution of detouring the dll entry point and catching DLL_PROCESS_DETACH. I found detouring FreeLibrary() to work as well but code must be added to detect when the module is actually unloaded or if the reference count is just being decreased. Necrolis' link about finding the reference count was handy for on method of doing so.</p>
  
  <p>I should note that I had problems with MSDetours not actually unloading the module from memory if a detour existed within it.</p>