title: Why does SetWindowsHookEx return 0?
body: <p>I'm trying to set a <code>WH_CBT</code> hook, and it return 0 all the time.
  I checked for error, and I got error 1428. I researched a little and found out that I have a problem with the <code>hMod</code> parameter, though I can't see what should I put in it instead of <code>null</code>. Does anyone know what I am doing wrong?</p>
  
  <p>This is my code:</p>
  
  <pre><code>#include "stdafx.h"
  #include "Windows.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  HHOOK hookHandle;
  
  LRESULT CALLBACK CBTProc( int nCode,  WPARAM wParam,  LPARAM lParam);
  
  int _tmain(int argc, _TCHAR* argv[]) 
  {
  hookHandle = SetWindowsHookEx(WH_CBT,CBTProc,NULL,0);
  
   if(hookHandle == NULL) 
   {
    cout &lt;&lt; "ERROR CREATING HOOK: ";
    cout &lt;&lt; GetLastError() &lt;&lt; endl;
    getchar();
    return 0;
   }
  
   MSG message;
  
   while(GetMessage(&amp;message, NULL, 0, 0) != 0) 
   {
    TranslateMessage( &amp;message );
    DispatchMessage( &amp;message );
   }
  
  
  
   cout &lt;&lt; "Press any key to quit...";
   getchar();
  
   UnhookWindowsHookEx(hookHandle);
  
   return 0;
  }
  
  LRESULT CALLBACK CBTProc( int nCode,WPARAM wParam, LPARAM lParam)
  {
  cout &lt;&lt; "hello" &lt;&lt; endl;
      return CallNextHookEx(hookHandle, nCode, 
              wParam, lParam);
  }
  </code></pre>
  
  <p>P.S. I apologize if the code has stupid elements about it. I'm not a newbie to programming, just to C++.</p>