<?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[KeyboardHook Programmfokus]]></title><description><![CDATA[<p>hallo zusammen</p>
<p>Ich hab mich seit ner Weile mit WinApi beschäftigt und mir zum Ziel gesetzt n funktionierenden KeyboardHook zu programmieren. Hab sämmtliche Threads die dieses Thema behandeln schon durchgeackert, sowie das DLL-TUT im bereich WinAPI FAQ/Archiv. Mit all dem gesammelten Wissen und den gesammelten Informationen hab ich folgenden Code zusammengestellt.</p>
<p><strong>Problem:</strong> Die InstallHook / DeinstallHook Funktionen funktionieren und können sauber aufrufen werden. Doch wenn ich den Hook gesetzt hab und dann n paar Tasten drücken zum Testen, führt das Prog die KeyboardProc-CALLBACK Funktion nicht aus (Kein &quot;printf (&quot;keystroke\n&quot;, siehe Code);&quot;.</p>
<p><em>Compiler: LabWindows/CVI 8.5 Compiler</em></p>
<p>Schauts euch ma an:</p>
<pre><code class="language-cpp">//Dll:*************************************************************************

//maindll.h********************************************************************

//-- include-Anweisungen ------------------------------------------------------
#include &lt;windows.h&gt;
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//This function installs the Keyboard hook. 
__declspec(dllexport) void InstallHook(void);
//This function removes the previously installed hook.
__declspec(dllexport) void UninstallHook(void);
//This function is called when the keyboard is operated.
LRESULT CALLBACK KeyboardProc (int ncode,WPARAM wparam,LPARAM lparam);
//-----------------------------------------------------------------------------

//maindll.c********************************************************************

//-- include-Anweisungen ------------------------------------------------------
#include &lt;windows.h&gt;
#include &lt;ansi_c.h&gt; 
#include &quot;dllmain.h&quot; 
//-----------------------------------------------------------------------------

//Shared-Data-Segment
#pragma data_seg(&quot;Shared&quot;)
HHOOK hook = NULL; // Handle  Hook (als &quot;shared&quot;)
#pragma data_seg()

#pragma comment (linker, &quot;/section:Shared,RWS&quot;)	//linker directive  

HINSTANCE hinstance = NULL;	//Handle Dll

//Dll-Hauptfunktion
//-----------------------------------------------------------------------------
BOOL APIENTRY DllMain (HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{		
	hinstance = hModule;
   	return TRUE;
}
//-----------------------------------------------------------------------------

//Installationsfunktion
//-----------------------------------------------------------------------------
__declspec(dllexport) void InstallHook (void)
{
	hook = NULL;
	hook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hinstance, 0);
	if(hook != NULL) printf(&quot;Install hook sucessful\n&quot;);	//Installation überprüfung
}

//-----------------------------------------------------------------------------

//Deinstallationsfunktion
//-----------------------------------------------------------------------------
__declspec(dllexport) void UninstallHook (void)
{
	if(hook != NULL)
	{
		UnhookWindowsHookEx(hook);
		hook = NULL;
		printf(&quot;Uninstall hook sucessful\n&quot;);	//Deinstallation überprüfung
	}
}

//-----------------------------------------------------------------------------

//Keystroke Callback
//-----------------------------------------------------------------------------
LRESULT CALLBACK KeyboardProc (int ncode, WPARAM wparam, LPARAM lparam)
{
	if(ncode&gt;=0)
	{
		if((lparam &amp; 0x80000000) == 0x00000000)	//Keystroke oder Keyrelease?
		{  
			printf (&quot;keystroke\n&quot;);	//Callbackaufruf überprüfen			
		}
	}
	return ( CallNextHookEx(hook,ncode,wparam,lparam) ); //Nächster Hook in der Hook-Kette aufrufen

}

//Hauptprogramm:***************************************************************

//kl.h*************************************************************************

void SWSetUp (void);
void SWCleanUp (void);

//kl.c*************************************************************************

//-- include-Anweisungen ------------------------------------------------------
#include &lt;windows.h&gt;
#include &lt;ansi_c.h&gt;
#include &quot;kl.h&quot;
//-----------------------------------------------------------------------------

//-- Typendeklarationen -------------------------------------------------------
typedef void (*InstallHookType)(void);
typedef void (*UninstallHookType)(void);
//-----------------------------------------------------------------------------

HINSTANCE DllHandle;
BOOL fFreeResult;

//Hauptfunktion
//-----------------------------------------------------------------------------
void main (void)
{  
	SWSetUp();
	//maincode 
	getchar();	//zum drücken von paar tasten benötigt
	SWCleanUp();
	return;
}
//-----------------------------------------------------------------------------

//Software initalisieren
//-----------------------------------------------------------------------------
void SWSetUp (void)
{
	InstallHookType InstallFunc;

	//dll laden
	DllHandle = LoadLibrary(&quot;klDll.dll&quot;);
	//hook installieren
	if (DllHandle)
	{
		InstallFunc = (InstallHookType) GetProcAddress (DllHandle, &quot;InstallHook&quot;);// Die Einsprungadresse abfragen
		if (InstallFunc)
		{
			(*InstallFunc) (); 
		}  
	}	
	return;
}
//-----------------------------------------------------------------------------

//Software deinitalisieren
//-----------------------------------------------------------------------------
void SWCleanUp (void)
{
	UninstallHookType UninstallFunc;

	//hook deinstallieren
	if (DllHandle)
	{
		UninstallFunc = (UninstallHookType) GetProcAddress (DllHandle, &quot;UninstallHook&quot;);// Die Einsprungadresse abfragen
		if (UninstallFunc)
		{
			(*UninstallFunc) ();
		}
	}
	//dll entladen
	fFreeResult = FreeLibrary(DllHandle);
	return;
}
//-----------------------------------------------------------------------------
</code></pre>
<p>Bin um jede Hilfe dankbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/213802/keyboardhook-programmfokus</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 20:58:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/213802.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 May 2008 11:03:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Wed, 04 Jun 2008 11:45:00 GMT]]></title><description><![CDATA[<p>hallo zusammen</p>
<p>Ich hab mich seit ner Weile mit WinApi beschäftigt und mir zum Ziel gesetzt n funktionierenden KeyboardHook zu programmieren. Hab sämmtliche Threads die dieses Thema behandeln schon durchgeackert, sowie das DLL-TUT im bereich WinAPI FAQ/Archiv. Mit all dem gesammelten Wissen und den gesammelten Informationen hab ich folgenden Code zusammengestellt.</p>
<p><strong>Problem:</strong> Die InstallHook / DeinstallHook Funktionen funktionieren und können sauber aufrufen werden. Doch wenn ich den Hook gesetzt hab und dann n paar Tasten drücken zum Testen, führt das Prog die KeyboardProc-CALLBACK Funktion nicht aus (Kein &quot;printf (&quot;keystroke\n&quot;, siehe Code);&quot;.</p>
<p><em>Compiler: LabWindows/CVI 8.5 Compiler</em></p>
<p>Schauts euch ma an:</p>
<pre><code class="language-cpp">//Dll:*************************************************************************

//maindll.h********************************************************************

//-- include-Anweisungen ------------------------------------------------------
#include &lt;windows.h&gt;
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//This function installs the Keyboard hook. 
__declspec(dllexport) void InstallHook(void);
//This function removes the previously installed hook.
__declspec(dllexport) void UninstallHook(void);
//This function is called when the keyboard is operated.
LRESULT CALLBACK KeyboardProc (int ncode,WPARAM wparam,LPARAM lparam);
//-----------------------------------------------------------------------------

//maindll.c********************************************************************

//-- include-Anweisungen ------------------------------------------------------
#include &lt;windows.h&gt;
#include &lt;ansi_c.h&gt; 
#include &quot;dllmain.h&quot; 
//-----------------------------------------------------------------------------

//Shared-Data-Segment
#pragma data_seg(&quot;Shared&quot;)
HHOOK hook = NULL; // Handle  Hook (als &quot;shared&quot;)
#pragma data_seg()

#pragma comment (linker, &quot;/section:Shared,RWS&quot;)	//linker directive  

HINSTANCE hinstance = NULL;	//Handle Dll

//Dll-Hauptfunktion
//-----------------------------------------------------------------------------
BOOL APIENTRY DllMain (HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{		
	hinstance = hModule;
   	return TRUE;
}
//-----------------------------------------------------------------------------

//Installationsfunktion
//-----------------------------------------------------------------------------
__declspec(dllexport) void InstallHook (void)
{
	hook = NULL;
	hook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hinstance, 0);
	if(hook != NULL) printf(&quot;Install hook sucessful\n&quot;);	//Installation überprüfung
}

//-----------------------------------------------------------------------------

//Deinstallationsfunktion
//-----------------------------------------------------------------------------
__declspec(dllexport) void UninstallHook (void)
{
	if(hook != NULL)
	{
		UnhookWindowsHookEx(hook);
		hook = NULL;
		printf(&quot;Uninstall hook sucessful\n&quot;);	//Deinstallation überprüfung
	}
}

//-----------------------------------------------------------------------------

//Keystroke Callback
//-----------------------------------------------------------------------------
LRESULT CALLBACK KeyboardProc (int ncode, WPARAM wparam, LPARAM lparam)
{
	if(ncode&gt;=0)
	{
		if((lparam &amp; 0x80000000) == 0x00000000)	//Keystroke oder Keyrelease?
		{  
			printf (&quot;keystroke\n&quot;);	//Callbackaufruf überprüfen			
		}
	}
	return ( CallNextHookEx(hook,ncode,wparam,lparam) ); //Nächster Hook in der Hook-Kette aufrufen

}

//Hauptprogramm:***************************************************************

//kl.h*************************************************************************

void SWSetUp (void);
void SWCleanUp (void);

//kl.c*************************************************************************

//-- include-Anweisungen ------------------------------------------------------
#include &lt;windows.h&gt;
#include &lt;ansi_c.h&gt;
#include &quot;kl.h&quot;
//-----------------------------------------------------------------------------

//-- Typendeklarationen -------------------------------------------------------
typedef void (*InstallHookType)(void);
typedef void (*UninstallHookType)(void);
//-----------------------------------------------------------------------------

HINSTANCE DllHandle;
BOOL fFreeResult;

//Hauptfunktion
//-----------------------------------------------------------------------------
void main (void)
{  
	SWSetUp();
	//maincode 
	getchar();	//zum drücken von paar tasten benötigt
	SWCleanUp();
	return;
}
//-----------------------------------------------------------------------------

//Software initalisieren
//-----------------------------------------------------------------------------
void SWSetUp (void)
{
	InstallHookType InstallFunc;

	//dll laden
	DllHandle = LoadLibrary(&quot;klDll.dll&quot;);
	//hook installieren
	if (DllHandle)
	{
		InstallFunc = (InstallHookType) GetProcAddress (DllHandle, &quot;InstallHook&quot;);// Die Einsprungadresse abfragen
		if (InstallFunc)
		{
			(*InstallFunc) (); 
		}  
	}	
	return;
}
//-----------------------------------------------------------------------------

//Software deinitalisieren
//-----------------------------------------------------------------------------
void SWCleanUp (void)
{
	UninstallHookType UninstallFunc;

	//hook deinstallieren
	if (DllHandle)
	{
		UninstallFunc = (UninstallHookType) GetProcAddress (DllHandle, &quot;UninstallHook&quot;);// Die Einsprungadresse abfragen
		if (UninstallFunc)
		{
			(*UninstallFunc) ();
		}
	}
	//dll entladen
	fFreeResult = FreeLibrary(DllHandle);
	return;
}
//-----------------------------------------------------------------------------
</code></pre>
<p>Bin um jede Hilfe dankbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1514181</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514181</guid><dc:creator><![CDATA[elDorado]]></dc:creator><pubDate>Wed, 04 Jun 2008 11:45:00 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Thu, 22 May 2008 12:53:37 GMT]]></title><description><![CDATA[<p>soweit ich das sehe, hast du keinen Aufruf von GetMessage bzw. Peek Message in deinem Hauptprogramm. irgendwo in der msdn steht aber *zu erinnern versuch* das du eine nachrichtenschleife brauchst.<br />
hoffe das ist richtig ist, ist nämlich schon ne weile her bei mir.<br />
alle angaben sind wie immer ohne gewähr <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1514279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514279</guid><dc:creator><![CDATA[Fencer]]></dc:creator><pubDate>Thu, 22 May 2008 12:53:37 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Thu, 22 May 2008 14:08:10 GMT]]></title><description><![CDATA[<p>Ich dachte ich brauch im Hauptprogramm nur ne GetMessage() wenn ich auch die Nachricht ans Hauptprogramm senden will, nicht? Wenn ich doch nur die KeyboardProc aufrufen lassen will ohne gross die Daten zu verarbeiten sollte das doch reichen, also das mit der printf-Überprüfung. Korrigiert mich wenn ich mich irre...<br />
(p.s. bin noch ziemlich unerfahren was WinAPI angeht, von dem her nich böse werden wenn ich hier komische Sachen von mir gebe :p )</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1514316</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514316</guid><dc:creator><![CDATA[elDorado]]></dc:creator><pubDate>Thu, 22 May 2008 14:08:10 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Thu, 22 May 2008 14:46:25 GMT]]></title><description><![CDATA[<p>versuch mal</p>
<pre><code class="language-cpp">//Anfang davor
	MSG msg;
	while(true)//durch abruchbedingung ersetzen
	{
		PeekMessage(&amp;msg,0,0,0,PM_NOREMOVE);
		Sleep(10);
	}
//rest...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1514360</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514360</guid><dc:creator><![CDATA[Fencer]]></dc:creator><pubDate>Thu, 22 May 2008 14:46:25 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 23 May 2008 07:17:07 GMT]]></title><description><![CDATA[<p>ok, die Callback-Funktion in der Dll wird nun aufgerufen, danke</p>
<p>nochwas:<br />
wenn ich doch was mit PostMessage() schicken will muss ich da n Fensterhandle (hWnd) angeben, zu dem die Nachricht gehen soll oder? Und wenn ich nun kein Fenster habe, sondern einfach das Programm das die Daten verarbeiten soll wie soll ich das anstellen das die Funktion (KeyboardProc) in der Dll die Daten an mein Hauptprogramm schickt, kann man da auch irgend n ProgrammHandle mitgeben oder wie funktioniert das? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1514803</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1514803</guid><dc:creator><![CDATA[elDorado]]></dc:creator><pubDate>Fri, 23 May 2008 07:17:07 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 23 May 2008 10:45:24 GMT]]></title><description><![CDATA[<p>Da brauchst du PostThreadMessage mit der &quot;Process Id&quot; deines Haupt Threads (kann man z.B. mit GetCurrentThreadId ermitteln und der Dll-Funktion als Parameter mitgeben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>btw: &quot;böse&quot; werd ich nur bei kommentaren wie &quot;booh ej is dat kage&quot;(rechtschreibung übernommen) <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1515014</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1515014</guid><dc:creator><![CDATA[Fencer]]></dc:creator><pubDate>Fri, 23 May 2008 10:45:24 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 23 May 2008 11:03:35 GMT]]></title><description><![CDATA[<p>Fencer schrieb:</p>
<blockquote>
<p>Da brauchst du PostThreadMessage mit der &quot;Process Id&quot; deines Haupt Threads</p>
</blockquote>
<p>Das is die von der Hauptfunktion oder? (<strong>hInstance</strong> bei mir jetzt)</p>
<pre><code class="language-cpp">int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                   PSTR szCmdLine, int iCmdShow)
{
//code
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1515029</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1515029</guid><dc:creator><![CDATA[elDorado]]></dc:creator><pubDate>Fri, 23 May 2008 11:03:35 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 23 May 2008 11:50:16 GMT]]></title><description><![CDATA[<p>Mach doch einfach einen neuen Parameter für die InstallHook function. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1515077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1515077</guid><dc:creator><![CDATA[Fencer]]></dc:creator><pubDate>Fri, 23 May 2008 11:50:16 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 23 May 2008 14:42:07 GMT]]></title><description><![CDATA[<p>Danke Fencer für die bisherige Hilfe</p>
<p>Funktioniert soweit nun alles, wenn ich nun die Daten an mein Hauptprogramm übergebe während das Hauptprogramm aktiv ist (Taskleiste -&gt; ausgewählt), bearbeitet es die Daten. Wenn ich aber nun irgendwo anders ne Taste drücke, solange das Hauptprogramm nicht aktiv ist wird nichts bearbeitet, was ja auch logisch ist!</p>
<p>Hat einer eine Idee wie ich mein Hauptprogramm dazu bringe auch zu arbeiten während ich n anderes Programm aktiv habe, ohne die Verarbeitung in der Dll zu machen? Ist das überhaupt möglich?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1515165</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1515165</guid><dc:creator><![CDATA[elDorado]]></dc:creator><pubDate>Fri, 23 May 2008 14:42:07 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 23 May 2008 14:53:48 GMT]]></title><description><![CDATA[<p>Gern geschehen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>vllt. wenn du beim SetWindowsHookEx mal WH_KEYBOARD_LL(siehe msdn) versuchst. ist aber nur ne vermutung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1515213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1515213</guid><dc:creator><![CDATA[Fencer]]></dc:creator><pubDate>Fri, 23 May 2008 14:53:48 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 23 May 2008 16:32:30 GMT]]></title><description><![CDATA[<p>muss ins shared datensegment, zeig dein code.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1515263</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1515263</guid><dc:creator><![CDATA[teppichklopfer]]></dc:creator><pubDate>Fri, 23 May 2008 16:32:30 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Sat, 24 May 2008 09:43:47 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">//Shared-Data-Segment
#pragma data_seg(&quot;Shared&quot;)
HHOOK hook = NULL; // Handle  Hook (als &quot;shared&quot;)
#pragma data_seg()

#pragma comment (linker, &quot;/section:Shared,RWS&quot;)    //linker directive
</code></pre>
<p>was muss sonst denn noch da rein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1515599</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1515599</guid><dc:creator><![CDATA[elDorado]]></dc:creator><pubDate>Sat, 24 May 2008 09:43:47 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Sat, 24 May 2008 10:47:05 GMT]]></title><description><![CDATA[<p>die process id natürlich, ist doch sonnenklar wie schwarzbrot.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1515633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1515633</guid><dc:creator><![CDATA[teppichklopfer]]></dc:creator><pubDate>Sat, 24 May 2008 10:47:05 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 30 May 2008 13:13:21 GMT]]></title><description><![CDATA[<p>Ok is mir nun klar warum die da rein muss.</p>
<p>Ich übergebe der Dll die ThreadID meines Hauptprogrammes mit der InstallHook-Funktion und speichere sie in myAPP.</p>
<p>So sieht mein shared nun aus:</p>
<pre><code class="language-cpp">//Dll.c
//Shared data segment
#pragma data_seg(&quot;Shared&quot;)
HHOOK hook = NULL;  // HookHandle (als &quot;shared&quot; Deklariert)
DWORD myApp; //ThreadId des Programmes an das die Daten gesendet werden sollen
#pragma data_seg()
</code></pre>
<p>Die Callback-Funktion wird immer ordnungsgemäss aufgerufen:</p>
<pre><code class="language-cpp">//Dll.c
LRESULT CALLBACK KeyboardProc (int ncode, WPARAM wParam, LPARAM lParam)
{
	if(ncode&gt;=0)
	{
		if((lParam &amp; 0xE0000000) == 0x00000000) //Key filter
		{  
//			Beep(1700,100);
			PostThreadMessage(myApp, WM_USER+100, wParam, lParam); //Daten an Hauptprogramm senden
		}
	}
	return ( CallNextHookEx(hook,ncode,wParam,lParam) ); //Nächster Hook in der Hook-Kette aufrufen

}
</code></pre>
<p>So sieht meine Hauptschleife im Hauptprogramm nun aus die die Daten erhalten soll:</p>
<pre><code class="language-cpp">//hauptprogramm.c
while (msg.wParam != 27) //Austrittsbedinung erfüllt bei drücken von Esc
   {	
		GetMessage(&amp;msg, NULL, 0, 0);
		if(msg.message == WM_USER+100)
		{
			KeyStrokeProcessing(msg.wParam, msg.lParam); //Daten verarbeiten
		}
      DispatchMessage(&amp;msg); //MSG verteilen
   }
</code></pre>
<p>Wenn ich mein Hauptprogramm aktiv habe kriegt es die Daten, sobald ich aber n anderes Programm aktiviere erhält es die Daten nicht mehr, die Callback-Funktion in der Dll wird aber aufgerufen, an was kann das liegen?</p>
<p>mfg elDorado</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1519732</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1519732</guid><dc:creator><![CDATA[elDorado]]></dc:creator><pubDate>Fri, 30 May 2008 13:13:21 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Thu, 05 Jun 2008 07:14:36 GMT]]></title><description><![CDATA[<p>Habe ungefähr das selbe Problem und bis jetzt noch keine Lösung gefunden, bleib aber dran.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1522940</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1522940</guid><dc:creator><![CDATA[CheffKoch]]></dc:creator><pubDate>Thu, 05 Jun 2008 07:14:36 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 06 Jun 2008 05:36:35 GMT]]></title><description><![CDATA[<p>hab bei anderen projekten gesehen das die vor der PostMessage in der dll zuerst das handle des fensters mithilfe von FindWindow suchen und dann direkt dahin schicken. veruch doch mal n fenster zu erstellen, es dann aber nicht anzuzeigen, da ich mal annehme das dein programm ja eigentlich kein gui haben soll, mehr fällt mir dazu au ned ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1523769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1523769</guid><dc:creator><![CDATA[hansmaulwurf]]></dc:creator><pubDate>Fri, 06 Jun 2008 05:36:35 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Fri, 06 Jun 2008 06:35:44 GMT]]></title><description><![CDATA[<p>get last error <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1523789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1523789</guid><dc:creator><![CDATA[reduziert und deformiert]]></dc:creator><pubDate>Fri, 06 Jun 2008 06:35:44 GMT</pubDate></item><item><title><![CDATA[Reply to KeyboardHook Programmfokus on Tue, 10 Jun 2008 11:36:32 GMT]]></title><description><![CDATA[<p>was soll ich nu mit der Antwort anfangen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1526300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1526300</guid><dc:creator><![CDATA[Cheffkoch]]></dc:creator><pubDate>Tue, 10 Jun 2008 11:36:32 GMT</pubDate></item></channel></rss>