<?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[KeyHook - Keine Fehler, aber tut nix]]></title><description><![CDATA[<p>Hallo, ich habe aus der FAQ dieses KeyHook mal probiert, ich hab's soweit hinbekommen, habe auch alles beachtet und so, nur wenn ich das Programm starte und ein paar Tasten drücke, macht die Funktion, die die Tasten abfangen sollte nichts. Was mache ich falsch? Habe ich etwas vergessen? - Hier die Codes, die ich verwende:</p>
<p>KeyHook.dll:</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#include &lt;windows.h&gt;
#pragma hdrstop
#define WM_KEYHOOK WM_USER+100
HHOOK ghhookKB;
HINSTANCE ghInst;
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
  ghInst = hinst;
  return (1);
}
extern &quot;C&quot; __declspec(dllexport) __stdcall void SetHook(void);
extern &quot;C&quot; __declspec(dllexport) __stdcall void RemoveHook(void);
extern &quot;C&quot; __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);
void __stdcall SetHook(void)
{
  HOOKPROC lpfnHookProc = GetProcAddress(GetModuleHandle(&quot;KeyHook.dll&quot;),&quot;CheckKey&quot;);
  ghhookKB = SetWindowsHookEx(WH_KEYBOARD, lpfnHookProc, ghInst, NULL);
}
void __stdcall RemoveHook(void)
{
  UnhookWindowsHookEx(ghhookKB);
}
DWORD __stdcall CheckKey(int nCode, WORD wParam, LONG lParam)
{
  HWND ghAppWnd = FindWindow(&quot;TKeyHookForm&quot;, 0);
  if((nCode &lt; 0) || nCode == HC_NOREMOVE)
    return CallNextHookEx(ghhookKB, nCode, wParam, lParam);

  // Skip if it's a repeat
  if(lParam &amp; 0x40000000)
    return CallNextHookEx(ghhookKB, nCode, wParam, lParam);

  // Send key information to the main window
  SendMessage(ghAppWnd, WM_KEYHOOK, 0, lParam);

  return CallNextHookEx(ghhookKB, nCode, wParam, lParam);
}
</code></pre>
<p>form.h:</p>
<pre><code class="language-cpp">#ifndef formH
#define formH
#define WM_KEYHOOK WM_USER+100
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;StdCtrls.hpp&gt;
#include &lt;Forms.hpp&gt;
class TForm2 : public TForm{
__published:	// IDE-managed Components
    TListBox *ListBox1;
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall FormCloseQuery(TObject *Sender, bool &amp;CanClose);
private:	// User declarations
    MESSAGE void __fastcall KeyHook(TMessage &amp;Message);
    BEGIN_MESSAGE_MAP
        MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook);
    END_MESSAGE_MAP(TForm);
public:
    __fastcall TForm2(TComponent* Owner);
};
extern PACKAGE TForm2 *Form2;
#endif
</code></pre>
<p>form.cpp:</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#pragma hdrstop
#include &quot;form.h&quot;
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
extern &quot;C&quot; __declspec(dllexport) __stdcall void SetHook(void);
extern &quot;C&quot; __declspec(dllexport) __stdcall void RemoveHook(void);
extern &quot;C&quot; __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);
TForm2 *Form2;
__fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
{
}
void __fastcall TForm2::FormCreate(TObject *Sender)
{
    SetHook();
}
void __fastcall TForm2::KeyHook(TMessage &amp;Message)
{
    char Key[80];
    GetKeyNameText(Message.LParam,Key,80);
    ShowMessage(&quot;lol&quot;);
    delete Key;
}
void __fastcall TForm2::FormCloseQuery(TObject *Sender, bool &amp;CanClose)
{
    RemoveHook();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/102931/keyhook-keine-fehler-aber-tut-nix</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 21:42:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/102931.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 Mar 2005 22:35:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Wed, 02 Mar 2005 22:37:11 GMT]]></title><description><![CDATA[<p>Hallo, ich habe aus der FAQ dieses KeyHook mal probiert, ich hab's soweit hinbekommen, habe auch alles beachtet und so, nur wenn ich das Programm starte und ein paar Tasten drücke, macht die Funktion, die die Tasten abfangen sollte nichts. Was mache ich falsch? Habe ich etwas vergessen? - Hier die Codes, die ich verwende:</p>
<p>KeyHook.dll:</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#include &lt;windows.h&gt;
#pragma hdrstop
#define WM_KEYHOOK WM_USER+100
HHOOK ghhookKB;
HINSTANCE ghInst;
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
  ghInst = hinst;
  return (1);
}
extern &quot;C&quot; __declspec(dllexport) __stdcall void SetHook(void);
extern &quot;C&quot; __declspec(dllexport) __stdcall void RemoveHook(void);
extern &quot;C&quot; __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);
void __stdcall SetHook(void)
{
  HOOKPROC lpfnHookProc = GetProcAddress(GetModuleHandle(&quot;KeyHook.dll&quot;),&quot;CheckKey&quot;);
  ghhookKB = SetWindowsHookEx(WH_KEYBOARD, lpfnHookProc, ghInst, NULL);
}
void __stdcall RemoveHook(void)
{
  UnhookWindowsHookEx(ghhookKB);
}
DWORD __stdcall CheckKey(int nCode, WORD wParam, LONG lParam)
{
  HWND ghAppWnd = FindWindow(&quot;TKeyHookForm&quot;, 0);
  if((nCode &lt; 0) || nCode == HC_NOREMOVE)
    return CallNextHookEx(ghhookKB, nCode, wParam, lParam);

  // Skip if it's a repeat
  if(lParam &amp; 0x40000000)
    return CallNextHookEx(ghhookKB, nCode, wParam, lParam);

  // Send key information to the main window
  SendMessage(ghAppWnd, WM_KEYHOOK, 0, lParam);

  return CallNextHookEx(ghhookKB, nCode, wParam, lParam);
}
</code></pre>
<p>form.h:</p>
<pre><code class="language-cpp">#ifndef formH
#define formH
#define WM_KEYHOOK WM_USER+100
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;StdCtrls.hpp&gt;
#include &lt;Forms.hpp&gt;
class TForm2 : public TForm{
__published:	// IDE-managed Components
    TListBox *ListBox1;
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall FormCloseQuery(TObject *Sender, bool &amp;CanClose);
private:	// User declarations
    MESSAGE void __fastcall KeyHook(TMessage &amp;Message);
    BEGIN_MESSAGE_MAP
        MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook);
    END_MESSAGE_MAP(TForm);
public:
    __fastcall TForm2(TComponent* Owner);
};
extern PACKAGE TForm2 *Form2;
#endif
</code></pre>
<p>form.cpp:</p>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;
#pragma hdrstop
#include &quot;form.h&quot;
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
extern &quot;C&quot; __declspec(dllexport) __stdcall void SetHook(void);
extern &quot;C&quot; __declspec(dllexport) __stdcall void RemoveHook(void);
extern &quot;C&quot; __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);
TForm2 *Form2;
__fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
{
}
void __fastcall TForm2::FormCreate(TObject *Sender)
{
    SetHook();
}
void __fastcall TForm2::KeyHook(TMessage &amp;Message)
{
    char Key[80];
    GetKeyNameText(Message.LParam,Key,80);
    ShowMessage(&quot;lol&quot;);
    delete Key;
}
void __fastcall TForm2::FormCloseQuery(TObject *Sender, bool &amp;CanClose)
{
    RemoveHook();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/736520</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/736520</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Wed, 02 Mar 2005 22:37:11 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Thu, 03 Mar 2005 13:18:56 GMT]]></title><description><![CDATA[<p>Naja, man sollte den aus der FAQ kopierten Code hald doch an und ab auch mal analysieren.</p>
<p>Folgende zwei Fragen an dich:<br />
a) hat nichts mit dem eigentlichen Problem zu tun, aber trotzdem ein interessanter und vor Allem wichtiger Punkt: Wieso &quot;delete Key&quot;?<br />
b) Überleg dir mal wie die DLL wohl deinem Formular mitteilt, das eine Taste gedrückt wurde.</p>
<p>-junix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/736647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/736647</guid><dc:creator><![CDATA[junix]]></dc:creator><pubDate>Thu, 03 Mar 2005 13:18:56 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Thu, 03 Mar 2005 22:52:31 GMT]]></title><description><![CDATA[<p>junix schrieb:</p>
<blockquote>
<p>a) hat nichts mit dem eigentlichen Problem zu tun, aber trotzdem ein interessanter und vor Allem wichtiger Punkt: Wieso &quot;delete Key&quot;?</p>
</blockquote>
<p>Speicherfreigabe</p>
<blockquote>
<p>b) Überleg dir mal wie die DLL wohl deinem Formular mitteilt, das eine Taste gedrückt wurde.</p>
</blockquote>
<p>Wenn das so einfach für mich wäre, würde ich das hier nicht posten... also ich weiß, mit welcer Funktion das zusammenhängt, aber ich weiß nicht, wie ich sie aufrufen soll oder besser gesagt: Wann...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737173</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737173</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Thu, 03 Mar 2005 22:52:31 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Thu, 03 Mar 2005 23:08:12 GMT]]></title><description><![CDATA[<p>OK, jetzt habe ich das Formular umbenannt in KeyHookForm, damit klappt das, die Zeile sehe ich schon... jetzt benenne ich die Form um in fMain (wie sie eigentlich heißen soll) und ändere die Zeile in der DLL entsprechend um, aber es läuft wieder nicht... was nun?</p>
<p>EDIT: OK, sorry, danke für die Hilfe, ich habs... shit... DLL muss ja noch compiliert werden xD - Naja, bin schon etwas müde ^^</p>
<p>- Windoof</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737178</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Thu, 03 Mar 2005 23:08:12 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Fri, 04 Mar 2005 06:29:56 GMT]]></title><description><![CDATA[<p>Windoof schrieb:</p>
<blockquote>
<p>junix schrieb:</p>
<blockquote>
<p>a) hat nichts mit dem eigentlichen Problem zu tun, aber trotzdem ein interessanter und vor Allem wichtiger Punkt: Wieso &quot;delete Key&quot;?</p>
</blockquote>
<p>Speicherfreigabe</p>
</blockquote>
<p>Dir sollte man die Finger abhacken und das Programmieren verbieten!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737208</guid><dc:creator><![CDATA[Wahrer des Niveaus]]></dc:creator><pubDate>Fri, 04 Mar 2005 06:29:56 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Fri, 04 Mar 2005 06:32:14 GMT]]></title><description><![CDATA[<p>Key ist nicht dynamisch, also brauchst du auch kein delete.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737210</guid><dc:creator><![CDATA[PuppetMaster2k]]></dc:creator><pubDate>Fri, 04 Mar 2005 06:32:14 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Fri, 04 Mar 2005 07:36:27 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/3286">@Windoof</a>: Ist es nicht ein herrliches Gefühl, nach 10min Arbeit seinen Fehler selber gefunden und dabei sogar verstanden zu haben wies funktioniert?</p>
<p>Bezüglich dem delete<br />
a) zu jedem &quot;new&quot; gehört ein &quot;delete&quot;<br />
b) zu jedem &quot;new []&quot; gehört ein &quot;delete []&quot;<br />
c) Von allem was nicht mit new selbst erstellt wurde oder in einer DOkumentation gesagt wurde, man müsse es löschen: <strong>Keep your hands off!</strong><br />
d) Für Stackobjekte gilt c).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737224</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737224</guid><dc:creator><![CDATA[junix]]></dc:creator><pubDate>Fri, 04 Mar 2005 07:36:27 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Fri, 04 Mar 2005 07:47:58 GMT]]></title><description><![CDATA[<p>Und wie gebe ich den Speicher eines char-Arrays sonst wieder frei...? bei normalem char geht das ja mi .~char(); (Destruktor) und bei Char-Arrays...? Mit .~char()[]; oder wie...? - Hab jetzt keinen BCB zur hand, aber einfach mal so als verständnisfrage.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737229</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737229</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Fri, 04 Mar 2005 07:47:58 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Fri, 04 Mar 2005 08:05:18 GMT]]></title><description><![CDATA[<p>Wenn das mit ~char geht, dann zahl ich dir ne kiste bier! Nur Klassen haben Destruktoren...</p>
<p>Stackobjekte werden ungültig nach Verlassen des Scopes.</p>
<p>Also durch eine &quot;}&quot;</p>
<p>-junix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737235</guid><dc:creator><![CDATA[junix]]></dc:creator><pubDate>Fri, 04 Mar 2005 08:05:18 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Fri, 04 Mar 2005 08:32:55 GMT]]></title><description><![CDATA[<p>Es sei denn der char wurde mit new erzeugt, dann gilt wieder (siehe junix vorletztes Posting) delete (für ein eizelnens char) oder delete[] (für ein char-Array).<br />
Verständnisfragen solcher Art werden in jedem C / C++ Grundlagenbuch, meist äußerst erschöpfend, behandelt. Leg Dir mal eins zu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737243</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737243</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 04 Mar 2005 08:32:55 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Fri, 04 Mar 2005 09:32:13 GMT]]></title><description><![CDATA[<p>junix schrieb:</p>
<blockquote>
<p>Wenn das mit ~char geht, dann zahl ich dir ne kiste bier! Nur Klassen haben Destruktoren...</p>
<p>Stackobjekte werden ungültig nach Verlassen des Scopes.</p>
<p>Also durch eine &quot;}&quot;</p>
<p>-junix</p>
</blockquote>
<p>Gut, dann schick den Kasten an folgende Adresse: ... Nein mal im Ernst: Das geht. Auch mit int geht das. Nur mit bool nicht... aber auch nur im BCB nicht, mit Dev-C++ kann man alle freigeben, auch bool... muss man sogar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737283</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Fri, 04 Mar 2005 09:32:13 GMT</pubDate></item><item><title><![CDATA[Reply to KeyHook - Keine Fehler, aber tut nix on Fri, 04 Mar 2005 09:44:54 GMT]]></title><description><![CDATA[<blockquote>
<p>Ein Destruktor wird implizit aufgerufen, wenn eine Variable ihren deklarierten Gültigkeitsbereich verläßt. Destruktoren für lokale Variablen werden aufgerufen, wenn der Block, in dem sie deklariert sind, nicht mehr aktiv ist. Bei globalen Variablen werden Destruktoren als Teil der Exit-Prozedur nach main aufgerufen.</p>
<p>Wenn Zeiger auf Objekte ungültig werden, wird nicht implizit ein Destruktor aufgerufen. Zum Löschen eines derartigen Objekts muß demnach der delete-Operator aufgerufen werden.</p>
<p>Destruktoren werden in genau der umgekehrten Reihenfolge wie die zugehörigen Konstruktoren aufgerufen (siehe Aufrufreihenfolge von Konstruktoren).</p>
</blockquote>
<p>Aus der BCB-Hilfe. Das wichtige Wörtchen ist implizit. Somit ist also schon der Gedanke daran, dne Destruktor (oder auch den Kostruktor) manuell aufzurufen sträflicher Unsinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/737294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/737294</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Fri, 04 Mar 2005 09:44:54 GMT</pubDate></item></channel></rss>