C++ WH_GETMESSAGE Hook in DLL injects the DLL itself into all Processes
<p>i got a WH_GETMESSAGE Hook in my DLL but if i inject the DLL into a Process, it seems like the DLL gets injected into other Processes. I don't know why that should happen...</p>

<pre><code>if(dwReason == DLL_PROCESS_ATTACH )
{
    g_pGlobals-&gt;dllModule = hModule;
</code></pre>

<p>in the DllMain Function i store the Module</p>

<p>and then i set the hook with</p>

<pre><code>m_hKeyboardHook = SetWindowsHookEx(WH_GETMESSAGE, KeyboardHook, g_pGlobals-&gt;dllModule, 0);

    MSG message;
    while (GetMessage(&amp;message, NULL, 0, 0)) {

        TranslateMessage(&amp;message);
        DispatchMessage(&amp;message);
    }

    UnhookWindowsHookEx(m_hKeyboardHook);
</code></pre>

<p>the hook it self looks like:</p>

<pre><code>LRESULT __stdcall KeyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
{

 if(nCode &gt;= 0 &amp;&amp; nCode == HC_ACTION)
 {
     MSG* pMsg = (MSG*)lParam;

    if(pMsg-&gt;message == WM_KEYDOWN)
        g_pMenu-&gt;OnKeyPressed(pMsg-&gt;wParam);

    if (pMsg-&gt;message == WM_CHAR)
        g_pMenu-&gt;OnCharPressed(pMsg-&gt;wParam);
  }

return CallNextHookEx(g_pWindowsHooks-&gt;GetKeyboardHook(), nCode, wParam, lParam);
}
</code></pre>

<p>and yeah g_pWindowsHooks->GetKeyboardHook() returns m_hKeyboardHook</p>

<p>Thanks for your help!</p>