title: Out-of-context SetWinEventHook() not getting any events
body: <p>Why is this program not getting any events ?</p>
  <p>This is a global (out-of-context) hook (with its message loop) that's configured for <code>[EVENT_MIN , EVENT_MAX]</code>, it should drown in events.</p>
  <p>Tried both Console &amp; Window types :</p>
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;thread&gt;
  
  using namespace std;
  
  HWINEVENTHOOK g_hook;
  bool stop = false;
  
  // Callback function that handles events.
  void CALLBACK HandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, 
    LONG idObject, LONG idChild, 
    DWORD dwEventThread, DWORD dwmsEventTime)
  {
    cout&lt;&lt;&quot;Got event &quot;&lt;&lt;event&lt;&lt;'\n'&lt;&lt;std::flush;
  }
  
  int EventHook() {
  
    cout &lt;&lt;&quot;thread EventHook running\n&quot;&lt;&lt;std::flush;
    g_hook = SetWinEventHook(
      EVENT_MIN , EVENT_MAX,  // Range of events.
      NULL,                   // Handle to DLL.
      HandleWinEvent,         // The callback.
      0, 0,                   // Process and thread IDs of interest (0 = all)
      WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS); // Flags.
    cout &lt;&lt;&quot;Hooked\n&quot;&lt;&lt;std::flush;
  
    MSG msg;
    while (PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE))
    {
      TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
      if(stop) return 0;
    }
    return 0;
  }
  
  // Both console &amp; window are eventless
  //int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
  //  int argc;
  //  auto *argv = CommandLineToArgvW(GetCommandLine(), &amp;argc);
  int main(int argc, char **argv){
  
    std::thread t1(EventHook); cout&lt;&lt;&quot;start thread EventHook\n&quot;&lt;&lt;std::flush;
    //Sleep(std::wcstoul(argv[1],nullptr,10) * 1000);
    Sleep(std::strtoul(argv[1],nullptr,10) * 1000);
  
    stop = true;
    t1.join();
  
    UnhookWinEvent(g_hook);
    return 0;
  }
  </code></pre>
  <p>Any help appreciated. Thank you.</p>