<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Keyboard Hook sendet keine Nachricht]]></title><description><![CDATA[<p>Hallo</p>
<p>wie der Titel schon sagt, möchte ich systemweit alle tastendrücke<br />
mitbekommen. dazu hab ich mir eine DLL geschrieben, die die Hookfunktion<br />
enthällt, und eine Testanwendung, die von der DLL Nachrichten bekommt.</p>
<p>Das klappt aber nicht, es kommt nix bei dem Fenster an <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>DLL.cpp</p>
<pre><code class="language-cpp">#pragma data_seg(&quot;shared&quot;)

HWND hWnd;
HINSTANCE hdll;
HHOOK hook;

#pragma data_seg()
#pragma comment(linker, &quot;/SECTION:shared,RWS&quot;)

LRESULT CALLBACK HookProc(int code, WPARAM wParam, LPARAM lParam)
{
	if (code == HC_ACTION)
		SendMessage(hWnd, WM_USER + 123, wParam, lParam);
	return CallNextHookEx(hook, code, wParam, lParam);
}

extern &quot;C&quot;
{
#define DLL __declspec(dllexport)

	DLL unsigned InstallHook()
	{
		if (hook)
			return 1;
		hook = SetWindowsHookEx(WH_KEYBOARD, HookProc, hdll, 0);
		return hook ? 1 : 0;
	}
	DLL void UninstallHook()
	{
		if (hook)
			UnhookWindowsHookEx(hook);
		hook = 0;
	}
	DLL void SetWindow(HWND wnd)
	{
		hWnd = wnd;
	}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH)
		hdll = hModule;
	return 1;
}
</code></pre>
<p>TEST.cpp</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc(HWND hWnd, unsigned msg, WPARAM wParam, LPARAM lParam)
{
	if (msg == WM_USER + 123)
		__asm int 3 // ruft den debugger auf
	return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE inst, HINSTANCE, char *, int)
{
	char buffer[5] = {0};
	*reinterpret_cast&lt;unsigned *&gt;(buffer) = GetTickCount(); // unique class name

	WNDCLASSA wc;
	ZeroMemory(&amp;wc, sizeof(wc));

	wc.hInstance = inst;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = buffer;

	RegisterClassA(&amp;wc);

	HWND hWnd = CreateWindowExA(0, wc.lpszClassName, &quot;dummy_window&quot;, 0, 0, 0, 0, 0, 0, 0, wc.hInstance, 0); // dummy window

	HMODULE dll = LoadLibraryA(&quot;hookdll&quot;);

	typedef unsigned (*tinitfunc)();
	typedef void (*texitfunc)();
	typedef void (*tsetfunc)(HWND);

	tinitfunc initfunc = (tinitfunc)GetProcAddress(dll, &quot;InstallHook&quot;);
	texitfunc exitfunc = (texitfunc)GetProcAddress(dll, &quot;UninstallHook&quot;);
	tsetfunc setfunc = (tsetfunc)GetProcAddress(dll, &quot;SetWindow&quot;);

	initfunc();
	setfunc(hWnd);

	MSG msg;
	while (GetMessage(&amp;msg, 0, 0, 0))
	{
		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
	}
}
</code></pre>
<p>Die DLL wird korrekt geladen, die funktionen sind auch richtig.</p>
<p>Das Fenster, auch wenn man es nicht sieht, wird auch erzeugt.</p>
<p>Warum bekomme ich keine Nachrichen?<br />
Wenn ich Manuell SendMessage in der TEST.exe verwende, kommt die<br />
Nachricht ganz normal an.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/237271/keyboard-hook-sendet-keine-nachricht</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Apr 2026 12:08:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/237271.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Mar 2009 15:34:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Keyboard Hook sendet keine Nachricht on Thu, 26 Mar 2009 15:34:26 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>wie der Titel schon sagt, möchte ich systemweit alle tastendrücke<br />
mitbekommen. dazu hab ich mir eine DLL geschrieben, die die Hookfunktion<br />
enthällt, und eine Testanwendung, die von der DLL Nachrichten bekommt.</p>
<p>Das klappt aber nicht, es kommt nix bei dem Fenster an <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>DLL.cpp</p>
<pre><code class="language-cpp">#pragma data_seg(&quot;shared&quot;)

HWND hWnd;
HINSTANCE hdll;
HHOOK hook;

#pragma data_seg()
#pragma comment(linker, &quot;/SECTION:shared,RWS&quot;)

LRESULT CALLBACK HookProc(int code, WPARAM wParam, LPARAM lParam)
{
	if (code == HC_ACTION)
		SendMessage(hWnd, WM_USER + 123, wParam, lParam);
	return CallNextHookEx(hook, code, wParam, lParam);
}

extern &quot;C&quot;
{
#define DLL __declspec(dllexport)

	DLL unsigned InstallHook()
	{
		if (hook)
			return 1;
		hook = SetWindowsHookEx(WH_KEYBOARD, HookProc, hdll, 0);
		return hook ? 1 : 0;
	}
	DLL void UninstallHook()
	{
		if (hook)
			UnhookWindowsHookEx(hook);
		hook = 0;
	}
	DLL void SetWindow(HWND wnd)
	{
		hWnd = wnd;
	}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH)
		hdll = hModule;
	return 1;
}
</code></pre>
<p>TEST.cpp</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc(HWND hWnd, unsigned msg, WPARAM wParam, LPARAM lParam)
{
	if (msg == WM_USER + 123)
		__asm int 3 // ruft den debugger auf
	return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE inst, HINSTANCE, char *, int)
{
	char buffer[5] = {0};
	*reinterpret_cast&lt;unsigned *&gt;(buffer) = GetTickCount(); // unique class name

	WNDCLASSA wc;
	ZeroMemory(&amp;wc, sizeof(wc));

	wc.hInstance = inst;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = buffer;

	RegisterClassA(&amp;wc);

	HWND hWnd = CreateWindowExA(0, wc.lpszClassName, &quot;dummy_window&quot;, 0, 0, 0, 0, 0, 0, 0, wc.hInstance, 0); // dummy window

	HMODULE dll = LoadLibraryA(&quot;hookdll&quot;);

	typedef unsigned (*tinitfunc)();
	typedef void (*texitfunc)();
	typedef void (*tsetfunc)(HWND);

	tinitfunc initfunc = (tinitfunc)GetProcAddress(dll, &quot;InstallHook&quot;);
	texitfunc exitfunc = (texitfunc)GetProcAddress(dll, &quot;UninstallHook&quot;);
	tsetfunc setfunc = (tsetfunc)GetProcAddress(dll, &quot;SetWindow&quot;);

	initfunc();
	setfunc(hWnd);

	MSG msg;
	while (GetMessage(&amp;msg, 0, 0, 0))
	{
		TranslateMessage(&amp;msg);
		DispatchMessage(&amp;msg);
	}
}
</code></pre>
<p>Die DLL wird korrekt geladen, die funktionen sind auch richtig.</p>
<p>Das Fenster, auch wenn man es nicht sieht, wird auch erzeugt.</p>
<p>Warum bekomme ich keine Nachrichen?<br />
Wenn ich Manuell SendMessage in der TEST.exe verwende, kommt die<br />
Nachricht ganz normal an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1686423</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1686423</guid><dc:creator><![CDATA[häckchen]]></dc:creator><pubDate>Thu, 26 Mar 2009 15:34:26 GMT</pubDate></item><item><title><![CDATA[Reply to Keyboard Hook sendet keine Nachricht on Sat, 28 Mar 2009 15:10:59 GMT]]></title><description><![CDATA[<p>Du musst den Hook so machen:</p>
<pre><code class="language-cpp">hook = SetWindowsHookEx(WH_KEYBOARD_LL, HookProc, hdll, 0);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1687483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1687483</guid><dc:creator><![CDATA[KLG7]]></dc:creator><pubDate>Sat, 28 Mar 2009 15:10:59 GMT</pubDate></item><item><title><![CDATA[Reply to Keyboard Hook sendet keine Nachricht on Sat, 28 Mar 2009 16:06:51 GMT]]></title><description><![CDATA[<p>KLG7 schrieb:</p>
<blockquote>
<p>Du musst den Hook so machen:</p>
<pre><code class="language-cpp">hook = SetWindowsHookEx(WH_KEYBOARD_LL, HookProc, hdll, 0);
</code></pre>
</blockquote>
<p>Nö wieso? WH_KEYBOARD_LL ist doch nur für low-level keyboard input events.<br />
WH_KEYBOARD stimmt schon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1687517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1687517</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 28 Mar 2009 16:06:51 GMT</pubDate></item><item><title><![CDATA[Reply to Keyboard Hook sendet keine Nachricht on Sun, 29 Mar 2009 08:57:19 GMT]]></title><description><![CDATA[<p>War bei mir aber so das der Hook erst gesendet hat wenn man ihn LL machte vorher bei mir nit</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1687716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1687716</guid><dc:creator><![CDATA[KLG7]]></dc:creator><pubDate>Sun, 29 Mar 2009 08:57:19 GMT</pubDate></item></channel></rss>