title: DLL implementing window hook crashes with "Faulting module name: myDll.DLL_unloaded"
body: <p>I have a DLL which uses certain hook functions, and it works OK on Windows 7 and XP. But on Windows 8, i get a crash when I cloase IE 10 or some other program.</p>
  
  <blockquote>
    <p>Faulting module name: myDll.DLL_unloaded</p>
  </blockquote>
  
  <p>Can you please tell me why this happens and how to fix it?</p>
  
  <p>By the way, if I run a program, such as IE, with admin privileges or in the Windows 7 or XP compatible mode, it won't crash.</p>
  
  <p>Here is part of my code:</p>
  
  <pre><code>if (checkWorking())
  {
    addString2File("C:\\dll.txt", "core online");
    // TRACE("core online!");
    HHOOK hHook = ::SetWindowsHookEx(WH_CALLWNDPROC, WindowHook, g_hModule, NULL);
    ::PostMessage(HWND_BROADCAST, WM_NULL, 0, 0);
  
    tools::security::SecurityAllAccess sa;
    HANDLE hSleepEvent = ::CreateEvent(sa, TRUE, FALSE, g_tszTermEventName);
    tools::security::GrantLowIntegrityAccess(SE_KERNEL_OBJECT, hSleepEvent);
    tools::endsession::WaitEndSession(hSleepEvent);
    ::UnhookWindowsHookEx(hHook);
  }
  else
  {
    TRACE("wrong start!");
  }
  </code></pre>