<?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[hook problem]]></title><description><![CDATA[<p>hola leute</p>
<p>hab mal das beispiel aus der FAQ 'tasten systemweit abfangen' ausprobiert und hab da so meine probleme. die dll bekommt zwar jeden tastendruck systemweit mit, jedoch bekommt das aufrufende programm nur die info ueber nen tastendruck wenn das programm selber den fokus hat.</p>
<p>hier mal bissl was von der dll:</p>
<pre><code class="language-cpp">bool __stdcall InstallHook(HWND t_hwnd)
{
   hWindow = t_hwnd;
   HOOKPROC hook_proc =  GetProcAddress(GetModuleHandle(&quot;obdll.dll&quot;), &quot;HookProc&quot;);

   if(hook_proc == 0)
      return 0;

   ghook = SetWindowsHookEx(WH_KEYBOARD, hook_proc, ghInstance, NULL);

   return ghook;
}

bool __stdcall UninstallHook(void)
{
   return UnhookWindowsHookEx(ghook);
}

extern &quot;C&quot; __declspec(dllexport) __stdcall DWORD HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
   if((nCode &lt; 0) || nCode == HC_NOREMOVE)
   {
      return CallNextHookEx(ghook, nCode, wParam, lParam);
   }

   char msg[120];
   sprintf(msg, &quot;SendMessage(hWindow, WM_KEYHOOK, 0, lParam);\nlparam: %i&quot;, (int)lParam);
   SendMessage(hWindow, WM_KEYHOOK, wParam, lParam);
   MessageBox(0, msg, &quot;DLL-Message&quot;, MB_OK); // nur damit ich seh ob SendMessage aufgerufen wurde

   return CallNextHookEx(ghook, nCode, wParam, lParam);
}
</code></pre>
<p>und was vom programm</p>
<pre><code class="language-cpp">/* zuerst die *.h */
/* diesen teil hab ich im publicbereich stehen */
void __fastcall KeyHook(TMessage &amp;Message);
   MESSAGE
      BEGIN_MESSAGE_MAP
         VCL_MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook);
      END_MESSAGE_MAP(TForm);

/* die funktion in der *.cpp */
void __fastcall TFMain::KeyHook(TMessage &amp;Message)
{
   char Key[80];
   GetKeyNameText(Message.LParam, Key, 80);
   Memo1-&gt;Lines-&gt;Add(AnsiString(&quot;MSG: &quot;) + Key);
}
</code></pre>
<p>sieht da jemand einen fehler ?<br />
die messagebox wird bei jedem tastendruck egal welches programm den focus hat aufgerufen. nur TFMain::KeyHook nicht.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/129727/hook-problem</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Jul 2026 00:39:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/129727.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Dec 2005 09:20:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to hook problem on Fri, 16 Dec 2005 09:20:43 GMT]]></title><description><![CDATA[<p>hola leute</p>
<p>hab mal das beispiel aus der FAQ 'tasten systemweit abfangen' ausprobiert und hab da so meine probleme. die dll bekommt zwar jeden tastendruck systemweit mit, jedoch bekommt das aufrufende programm nur die info ueber nen tastendruck wenn das programm selber den fokus hat.</p>
<p>hier mal bissl was von der dll:</p>
<pre><code class="language-cpp">bool __stdcall InstallHook(HWND t_hwnd)
{
   hWindow = t_hwnd;
   HOOKPROC hook_proc =  GetProcAddress(GetModuleHandle(&quot;obdll.dll&quot;), &quot;HookProc&quot;);

   if(hook_proc == 0)
      return 0;

   ghook = SetWindowsHookEx(WH_KEYBOARD, hook_proc, ghInstance, NULL);

   return ghook;
}

bool __stdcall UninstallHook(void)
{
   return UnhookWindowsHookEx(ghook);
}

extern &quot;C&quot; __declspec(dllexport) __stdcall DWORD HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
   if((nCode &lt; 0) || nCode == HC_NOREMOVE)
   {
      return CallNextHookEx(ghook, nCode, wParam, lParam);
   }

   char msg[120];
   sprintf(msg, &quot;SendMessage(hWindow, WM_KEYHOOK, 0, lParam);\nlparam: %i&quot;, (int)lParam);
   SendMessage(hWindow, WM_KEYHOOK, wParam, lParam);
   MessageBox(0, msg, &quot;DLL-Message&quot;, MB_OK); // nur damit ich seh ob SendMessage aufgerufen wurde

   return CallNextHookEx(ghook, nCode, wParam, lParam);
}
</code></pre>
<p>und was vom programm</p>
<pre><code class="language-cpp">/* zuerst die *.h */
/* diesen teil hab ich im publicbereich stehen */
void __fastcall KeyHook(TMessage &amp;Message);
   MESSAGE
      BEGIN_MESSAGE_MAP
         VCL_MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook);
      END_MESSAGE_MAP(TForm);

/* die funktion in der *.cpp */
void __fastcall TFMain::KeyHook(TMessage &amp;Message)
{
   char Key[80];
   GetKeyNameText(Message.LParam, Key, 80);
   Memo1-&gt;Lines-&gt;Add(AnsiString(&quot;MSG: &quot;) + Key);
}
</code></pre>
<p>sieht da jemand einen fehler ?<br />
die messagebox wird bei jedem tastendruck egal welches programm den focus hat aufgerufen. nur TFMain::KeyHook nicht.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/943335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/943335</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Fri, 16 Dec 2005 09:20:43 GMT</pubDate></item><item><title><![CDATA[Reply to hook problem on Fri, 16 Dec 2005 10:47:25 GMT]]></title><description><![CDATA[<p>re</p>
<p>hab den fehler gefunden. jedoch weiß ich nicht wie ich ihn bereinigen soll.<br />
in meiner dll hab ich in der InstallHook funktion die zeile:</p>
<pre><code class="language-cpp">hWindow = t_hwnd;
</code></pre>
<p>hWindow ist eine globale variable in der ich den HWND meines programms speichere. nun bin ich draufgekommen, das hWindow den wert 0 hat, wenn der focus bei einem anderen programm liegt.<br />
wie kann ich das machen das hWindow immer den wert behaelt ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/943392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/943392</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Fri, 16 Dec 2005 10:47:25 GMT</pubDate></item><item><title><![CDATA[Reply to hook problem on Fri, 16 Dec 2005 11:05:04 GMT]]></title><description><![CDATA[<p>Shared Memory nutzen.Stichwort CreateFileMapping</p>
<p>Den Quellcode von<br />
<a href="http://www.marquardtnet.info/cecke/dlls.3/3_chhook.html" rel="nofollow">http://www.marquardtnet.info/cecke/dlls.3/3_chhook.html</a><br />
kannst du anfordern</p>
]]></description><link>https://www.c-plusplus.net/forum/post/943412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/943412</guid><dc:creator><![CDATA[Christian211]]></dc:creator><pubDate>Fri, 16 Dec 2005 11:05:04 GMT</pubDate></item></channel></rss>