title: Hook from SetWindowsHookEx freezes process and don't get executed
body: <p>I tried to hook keyboard of one process, but code of hook don't get executed and process freezes when I press any key.
  I based my code on following post: <a href="https://stackoverflow.com/questions/820804/how-to-hook-external-process-with-setwindowshookex-and-wh-keyboard">How to hook external process with SetWindowsHookEx and WH_KEYBOARD</a></p>
  
  <p>Here is my code of dll:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  HINSTANCE hinst = NULL;
  #pragma data_seg(".shared")
  HHOOK hhk = NULL;
  #pragma data_seg()
  #pragma comment(linker, "/SECTION:.shared,RWS")
  
  LRESULT CALLBACK wireKeyboardProc(int code, WPARAM wParam, LPARAM lParam) {
      return CallNextHookEx(hhk, code, wParam, lParam);
  }
  
  extern "C" __declspec(dllexport) void install(unsigned long threadID) {
      hhk = SetWindowsHookEx(WH_KEYBOARD, wireKeyboardProc, hinst, threadID);
  }
  
  BOOL WINAPI DllMain(__in HINSTANCE hinstDLL, __in  DWORD fdwReason, __in  LPVOID lpvReserved) {
      hinst = hinstDLL;
      return TRUE;
  }
  </code></pre>
  
  <p>EDIT:
  After loading of dll I execute function install(), which secefully create hook, but for some reason function wireKeyboardProc don't get executed when key is pressed and process freezes. Any idea why this happen?</p>
  
  <p>EDIT 2:
  Here is also code of my exe:</p>
  
  <pre><code>unsigned long threadID = GetWindowThreadProcessId(hWnd, &amp;ProcessId);
  
      HINSTANCE hinst;
      hinst = LoadLibrary(_T("hookKbd32.dll"));
  
      if (hinst) {
          typedef void(*Install)(unsigned long);
          Install install = (Install)GetProcAddress(hinst, "install");
          install(threadID);
      }
  </code></pre>