<?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[Problem mit Globalem Keyhook]]></title><description><![CDATA[<p>Hallo, nach diesem Beispiel hier: <a href="http://www.mpcforum.com/archive/index.php/t-78344.html" rel="nofollow">http://www.mpcforum.com/archive/index.php/t-78344.html</a><br />
habe ich einen Keylogger mit globalem Keyhook ohne dll geschrieben. Das Problem ist nun, dass der Keylogger zwar unter Vista einwandfrei läuft, aber unter XP keine Taste aufzeichnet. Hier erstmal der Code:</p>
<pre><code class="language-cpp">#define _WIN32_WINNT 0x0400

#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;windows.h&gt;
#include &lt;time.h&gt;

using namespace std;

fstream datei;
char Buffer[50];

HHOOK hHook;
HINSTANCE hExe;

__declspec(dllexport) LRESULT CALLBACK HookProc ( int nCode,    WPARAM wParam,  LPARAM lParam)
{
    if  ((nCode == HC_ACTION) &amp;&amp; (wParam == WM_KEYDOWN))
    {
        KBDLLHOOKSTRUCT hookstruct = *((KBDLLHOOKSTRUCT*)lParam);
        char tile = (char)hookstruct.vkCode;
        sprintf(Buffer, &quot;You have just pressed: %c&quot;, tile);
        MessageBox(0, Buffer, NULL, MB_OK);
    }
     return CallNextHookEx(hHook, nCode, wParam, lParam);
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
hHook = SetWindowsHookEx( WH_KEYBOARD_LL, (HOOKPROC) HookProc, hExe, NULL);
while(GetMessage(NULL,NULL,0,0));
return UnhookWindowsHookEx(hHook);
}
</code></pre>
<p>Hat jemand ne Idee, warum der Keyhook nur unter Vista läuft?</p>
<p>Bitte keine Antworten bezüglich 'Höf auf Malware zu programmieren' -&gt; Das nervt, und vor allem mach ich das nicht, bin normalerweise in der Spieleprogrammierung tätig, wollte das hier nur mal ausprobieren <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/233243/problem-mit-globalem-keyhook</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 23:54:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/233243.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Feb 2009 15:00:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Globalem Keyhook on Mon, 02 Feb 2009 16:12:38 GMT]]></title><description><![CDATA[<p>Hallo, nach diesem Beispiel hier: <a href="http://www.mpcforum.com/archive/index.php/t-78344.html" rel="nofollow">http://www.mpcforum.com/archive/index.php/t-78344.html</a><br />
habe ich einen Keylogger mit globalem Keyhook ohne dll geschrieben. Das Problem ist nun, dass der Keylogger zwar unter Vista einwandfrei läuft, aber unter XP keine Taste aufzeichnet. Hier erstmal der Code:</p>
<pre><code class="language-cpp">#define _WIN32_WINNT 0x0400

#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;windows.h&gt;
#include &lt;time.h&gt;

using namespace std;

fstream datei;
char Buffer[50];

HHOOK hHook;
HINSTANCE hExe;

__declspec(dllexport) LRESULT CALLBACK HookProc ( int nCode,    WPARAM wParam,  LPARAM lParam)
{
    if  ((nCode == HC_ACTION) &amp;&amp; (wParam == WM_KEYDOWN))
    {
        KBDLLHOOKSTRUCT hookstruct = *((KBDLLHOOKSTRUCT*)lParam);
        char tile = (char)hookstruct.vkCode;
        sprintf(Buffer, &quot;You have just pressed: %c&quot;, tile);
        MessageBox(0, Buffer, NULL, MB_OK);
    }
     return CallNextHookEx(hHook, nCode, wParam, lParam);
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
hHook = SetWindowsHookEx( WH_KEYBOARD_LL, (HOOKPROC) HookProc, hExe, NULL);
while(GetMessage(NULL,NULL,0,0));
return UnhookWindowsHookEx(hHook);
}
</code></pre>
<p>Hat jemand ne Idee, warum der Keyhook nur unter Vista läuft?</p>
<p>Bitte keine Antworten bezüglich 'Höf auf Malware zu programmieren' -&gt; Das nervt, und vor allem mach ich das nicht, bin normalerweise in der Spieleprogrammierung tätig, wollte das hier nur mal ausprobieren <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656589</guid><dc:creator><![CDATA[Arr0ws]]></dc:creator><pubDate>Mon, 02 Feb 2009 16:12:38 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Globalem Keyhook on Mon, 02 Feb 2009 15:35:05 GMT]]></title><description><![CDATA[<p>Kann es sein, dass es etwas mit dem<br />
#define _WIN32_WINNT 0x0400<br />
zu tun hat?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656624</guid><dc:creator><![CDATA[Arr0ws]]></dc:creator><pubDate>Mon, 02 Feb 2009 15:35:05 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Globalem Keyhook on Mon, 02 Feb 2009 16:45:03 GMT]]></title><description><![CDATA[<p>Problem gelöst, es hatte nichts mit dem 0x400 zu tun:</p>
<p>Nach dem einstündigen Suchen nach einer Lösung bin ich draufgekommen, dass das Originalprogramm auf XP läuft, also die übliche Problemanalyse: Zeile für Zeile vom funktionierenden Programm zum nichtfunktionierenden. Langwierig aber wirkungsvoll: Nach 30 Minuten hatte ich den Fehler:</p>
<p>Diese Zeile:</p>
<pre><code class="language-cpp">hExe = GetModuleHandle(NULL);
</code></pre>
<p>gehört an den Anfang der WinMain.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656666</guid><dc:creator><![CDATA[Arr0ws]]></dc:creator><pubDate>Mon, 02 Feb 2009 16:45:03 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Globalem Keyhook on Wed, 04 Feb 2009 07:04:28 GMT]]></title><description><![CDATA[<p>Arr0ws schrieb:</p>
<blockquote>
<p>Diese Zeile:</p>
<pre><code class="language-cpp">hExe = GetModuleHandle(NULL);
</code></pre>
<p>gehört an den Anfang der WinMain.</p>
</blockquote>
<p>Unfug! Du brauchst das gar nicht weil WinMain hInstance freiwillig mitliefert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1657652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1657652</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 04 Feb 2009 07:04:28 GMT</pubDate></item></channel></rss>