<?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[Fehler aus der Hook DLL]]></title><description><![CDATA[<p>Weiß absolut nicht wo der Fehler liegt. Wäre für eine Hilfe Dankbar.</p>
<p>Erzeugen<br />
[C++ Warnung] dll.cpp(29): W8004 'lpfnHookProc' wurde ein Wert zugewiesen, der nie verwendet wird</p>
<p><strong>1. Code aus der dll.cpp</strong><br />
[cpp]<br />
//---------------------------------------------------------------------------</p>
<p>#include &lt;vcl.h&gt;<br />
#include &lt;windows.h&gt;<br />
#include &lt;winuser.h&gt;<br />
#pragma hdrstop<br />
//---------------------------------------------------------------------------</p>
<p>#define WM_KEYHOOK WM_USER+100<br />
HHOOK ghhookKB;<br />
HINSTANCE ghInst;<br />
#pragma argsused<br />
//---------------------------------------------------------------------------</p>
<p>int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)<br />
{<br />
ghInst = hinst;<br />
return (1);<br />
}<br />
//---------------------------------------------------------------------------</p>
<p>extern &quot;C&quot; __declspec(dllexport) __stdcall void SetHook(void);<br />
extern &quot;C&quot; __declspec(dllexport) __stdcall void RemoveHook(void);<br />
extern &quot;C&quot; __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);<br />
//---------------------------------------------------------------------------</p>
<p>void __stdcall SetHook(void)<br />
{<br />
<strong>HOOKPROC lpfnHookProc = NULL;</strong>// Fehlermeldung kommt von hier<br />
lpfnHookProc = GetProcAddress(GetModuleHandle(&quot;keydll.dll&quot;),&quot;CheckKey&quot;);<br />
ghhookKB = SetWindowsHookEx(WH_KEYBOARD, lpfnHookProc, ghInst, NULL);<br />
}<br />
//---------------------------------------------------------------------------</p>
<p>void __stdcall RemoveHook(void)<br />
{<br />
UnhookWindowsHookEx(ghhookKB);<br />
}<br />
//---------------------------------------------------------------------------</p>
<p>DWORD __stdcall CheckKey(int nCode, WORD wParam, LONG lParam)<br />
{<br />
HWND ghAppWnd = FindWindow(&quot;TForm1&quot;, 0);<br />
if((nCode &lt; 0) || nCode == HC_NOREMOVE)<br />
return CallNextHookEx(ghhookKB, nCode, wParam, lParam);</p>
<p>// Skip if it's a repeat<br />
if(lParam &amp; 0x40000000)<br />
return CallNextHookEx(ghhookKB, nCode, wParam, lParam);</p>
<p>// Send key information to the main window<br />
SendMessage(ghAppWnd, WM_KEYHOOK, 0, lParam);</p>
<p>return CallNextHookEx(ghhookKB, nCode, wParam, lParam);<br />
}<br />
//---------------------------------------------------------------------------<br />
[/cpp]</p>
<p><strong>2. Code aus der Mainform.h</strong></p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#ifndef mainformH
#define mainformH
#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;
#include &lt;Menus.hpp&gt;
//---------------------------------------------------------------------------

#define WM_TRAYNOTIFY  (WM_USER + 1001)

class TForm1 : public TForm
{
__published:	// IDE-managed Components
    TPopupMenu *PopupMenu1;
    TMenuItem *Unload1;
    TButton *UnloadBtn;
        TListBox *ListBox1;
      void __fastcall UnloadBtnClick(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &amp;Key,
          TShiftState Shift);
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall FormDestroy(TObject *Sender);

private:	// User declarations
    Graphics::TIcon *TrayIcon;
    void __fastcall KeyHook(TMessage &amp;Message);
    void __fastcall WMTrayNotify(TMessage &amp;Msg);
    void __fastcall RemoveIcon();
    void __fastcall AddIcon();
    void __fastcall AppOnMinimize(TObject *Sender);
    void __fastcall AppOnRestore(TObject *Sender);
    BEGIN_MESSAGE_MAP 
      MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook)
      MESSAGE_HANDLER(WM_TRAYNOTIFY,TMessage,WMTrayNotify) 
    END_MESSAGE_MAP(TForm); 

public:		// User declarations
    __fastcall TKeyHookForm(TComponent* Owner);
    __fastcall TForm1(TComponent* Owner);
    __fastcall ~TForm1();

//BEGIN_MESSAGE_MAP

//END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
</code></pre>
<p><strong>3. Code aus der Mainform.ccp</strong></p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#include &lt;vcl.h&gt;
#pragma hdrstop

const int IDC_TRAY1      = 1005;
const char *HINT_MESSAGE = &quot;Rechtsklick Öffnet&quot;;

#include &lt;shellapi.h&gt;
#include &quot;mainform.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;

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);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    // Load the icon from the EXE's resources
    TrayIcon = new Graphics::TIcon;
    TrayIcon-&gt;Handle=LoadImage(HInstance,
                              &quot;LITTLEICON&quot;,
                              IMAGE_ICON,
                              0,0,
                              0);

    // Add the icon to the taskbar
    AddIcon();

    Application-&gt;OnMinimize = AppOnMinimize;
    Application-&gt;OnRestore  = AppOnRestore;
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
    // Remove the icon from the tray, and delete
    // the TIcon pointer that we initially created.
    RemoveIcon();
    delete TrayIcon;
}

void __fastcall TForm1::WMTrayNotify(TMessage &amp;Msg)
{
    // The LPARAM of the message identifies the type of mouse message.
    // When they right click, show the popup menu. When they double
    // click with the left mouse, show the form.
    switch(Msg.LParam)
    {
        case WM_RBUTTONUP:
            POINT WinPoint;           // find the mouse cursor
            GetCursorPos(&amp;WinPoint);  // using api function, store
            SetForegroundWindow(Handle);
            PopupMenu1-&gt;Popup(WinPoint.x,WinPoint.y);
            PostMessage(Handle, WM_NULL, 0,0);
            break;
        case WM_LBUTTONDBLCLK:
            Application-&gt;Restore();
            break;
    }
}

//---------------------------------------------------------------------------
void __fastcall TForm1::UnloadBtnClick(TObject *Sender)
{
    // Terminate the app when they choose the upload option
    Application-&gt;Terminate();
}

void __fastcall TForm1::AddIcon()
{
    // Use the Shell_NotifyIcon API function to
    // add the icon to the tray.
    NOTIFYICONDATA IconData;
    IconData.cbSize = sizeof(NOTIFYICONDATA);
    IconData.uID    = IDC_TRAY1;
    IconData.hWnd   = Handle;
    IconData.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
    IconData.uCallbackMessage = WM_TRAYNOTIFY;
    lstrcpy(IconData.szTip, HINT_MESSAGE);
    IconData.hIcon  = TrayIcon-&gt;Handle;

    Shell_NotifyIcon(NIM_ADD,&amp;IconData);
}

void __fastcall TForm1::RemoveIcon()
{
    NOTIFYICONDATA IconData;
    IconData.cbSize = sizeof(NOTIFYICONDATA);
    IconData.uID    = IDC_TRAY1;
    IconData.hWnd   = Handle;
    IconData.hIcon  = TrayIcon-&gt;Handle;

    Shell_NotifyIcon(NIM_DELETE,&amp;IconData);
}

//---------------------------------------------------------------------------
void __fastcall TForm1::AppOnMinimize(TObject *Sender)
{
    ShowWindow(Application-&gt;Handle, SW_HIDE);
    Visible = false;
}

void __fastcall TForm1::AppOnRestore(TObject *Sender)
{
    ShowWindow(Application-&gt;Handle, SW_SHOW);
    Visible = true;

    SetForegroundWindow(Handle);
}

//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &amp;Key,
      TShiftState Shift)
{
 if(Key == VK_F1)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-1&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F2)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-2&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F3)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-3&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F4)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-4&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F5)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-5&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F6)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-6&quot;,&quot;Test&quot;,MB_OK);
 }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::KeyHook(TMessage &amp;Message)
{
  char Key[80];
  GetKeyNameText(Message.LParam, Key, 80);
  ListBox1-&gt;Items-&gt;Add(Key);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
SetHook();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
RemoveHook();
}
//---------------------------------------------------------------------------
</code></pre>
<p>MFG Praetorianer</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/86814/fehler-aus-der-hook-dll</link><generator>RSS for Node</generator><lastBuildDate>Fri, 03 Jul 2026 18:29:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/86814.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Sep 2004 17:30:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler aus der Hook DLL on Wed, 22 Sep 2004 17:43:23 GMT]]></title><description><![CDATA[<p>Weiß absolut nicht wo der Fehler liegt. Wäre für eine Hilfe Dankbar.</p>
<p>Erzeugen<br />
[C++ Warnung] dll.cpp(29): W8004 'lpfnHookProc' wurde ein Wert zugewiesen, der nie verwendet wird</p>
<p><strong>1. Code aus der dll.cpp</strong><br />
[cpp]<br />
//---------------------------------------------------------------------------</p>
<p>#include &lt;vcl.h&gt;<br />
#include &lt;windows.h&gt;<br />
#include &lt;winuser.h&gt;<br />
#pragma hdrstop<br />
//---------------------------------------------------------------------------</p>
<p>#define WM_KEYHOOK WM_USER+100<br />
HHOOK ghhookKB;<br />
HINSTANCE ghInst;<br />
#pragma argsused<br />
//---------------------------------------------------------------------------</p>
<p>int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)<br />
{<br />
ghInst = hinst;<br />
return (1);<br />
}<br />
//---------------------------------------------------------------------------</p>
<p>extern &quot;C&quot; __declspec(dllexport) __stdcall void SetHook(void);<br />
extern &quot;C&quot; __declspec(dllexport) __stdcall void RemoveHook(void);<br />
extern &quot;C&quot; __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);<br />
//---------------------------------------------------------------------------</p>
<p>void __stdcall SetHook(void)<br />
{<br />
<strong>HOOKPROC lpfnHookProc = NULL;</strong>// Fehlermeldung kommt von hier<br />
lpfnHookProc = GetProcAddress(GetModuleHandle(&quot;keydll.dll&quot;),&quot;CheckKey&quot;);<br />
ghhookKB = SetWindowsHookEx(WH_KEYBOARD, lpfnHookProc, ghInst, NULL);<br />
}<br />
//---------------------------------------------------------------------------</p>
<p>void __stdcall RemoveHook(void)<br />
{<br />
UnhookWindowsHookEx(ghhookKB);<br />
}<br />
//---------------------------------------------------------------------------</p>
<p>DWORD __stdcall CheckKey(int nCode, WORD wParam, LONG lParam)<br />
{<br />
HWND ghAppWnd = FindWindow(&quot;TForm1&quot;, 0);<br />
if((nCode &lt; 0) || nCode == HC_NOREMOVE)<br />
return CallNextHookEx(ghhookKB, nCode, wParam, lParam);</p>
<p>// Skip if it's a repeat<br />
if(lParam &amp; 0x40000000)<br />
return CallNextHookEx(ghhookKB, nCode, wParam, lParam);</p>
<p>// Send key information to the main window<br />
SendMessage(ghAppWnd, WM_KEYHOOK, 0, lParam);</p>
<p>return CallNextHookEx(ghhookKB, nCode, wParam, lParam);<br />
}<br />
//---------------------------------------------------------------------------<br />
[/cpp]</p>
<p><strong>2. Code aus der Mainform.h</strong></p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#ifndef mainformH
#define mainformH
#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;
#include &lt;Menus.hpp&gt;
//---------------------------------------------------------------------------

#define WM_TRAYNOTIFY  (WM_USER + 1001)

class TForm1 : public TForm
{
__published:	// IDE-managed Components
    TPopupMenu *PopupMenu1;
    TMenuItem *Unload1;
    TButton *UnloadBtn;
        TListBox *ListBox1;
      void __fastcall UnloadBtnClick(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &amp;Key,
          TShiftState Shift);
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall FormDestroy(TObject *Sender);

private:	// User declarations
    Graphics::TIcon *TrayIcon;
    void __fastcall KeyHook(TMessage &amp;Message);
    void __fastcall WMTrayNotify(TMessage &amp;Msg);
    void __fastcall RemoveIcon();
    void __fastcall AddIcon();
    void __fastcall AppOnMinimize(TObject *Sender);
    void __fastcall AppOnRestore(TObject *Sender);
    BEGIN_MESSAGE_MAP 
      MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook)
      MESSAGE_HANDLER(WM_TRAYNOTIFY,TMessage,WMTrayNotify) 
    END_MESSAGE_MAP(TForm); 

public:		// User declarations
    __fastcall TKeyHookForm(TComponent* Owner);
    __fastcall TForm1(TComponent* Owner);
    __fastcall ~TForm1();

//BEGIN_MESSAGE_MAP

//END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
</code></pre>
<p><strong>3. Code aus der Mainform.ccp</strong></p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------
#include &lt;vcl.h&gt;
#pragma hdrstop

const int IDC_TRAY1      = 1005;
const char *HINT_MESSAGE = &quot;Rechtsklick Öffnet&quot;;

#include &lt;shellapi.h&gt;
#include &quot;mainform.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;

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);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    // Load the icon from the EXE's resources
    TrayIcon = new Graphics::TIcon;
    TrayIcon-&gt;Handle=LoadImage(HInstance,
                              &quot;LITTLEICON&quot;,
                              IMAGE_ICON,
                              0,0,
                              0);

    // Add the icon to the taskbar
    AddIcon();

    Application-&gt;OnMinimize = AppOnMinimize;
    Application-&gt;OnRestore  = AppOnRestore;
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
    // Remove the icon from the tray, and delete
    // the TIcon pointer that we initially created.
    RemoveIcon();
    delete TrayIcon;
}

void __fastcall TForm1::WMTrayNotify(TMessage &amp;Msg)
{
    // The LPARAM of the message identifies the type of mouse message.
    // When they right click, show the popup menu. When they double
    // click with the left mouse, show the form.
    switch(Msg.LParam)
    {
        case WM_RBUTTONUP:
            POINT WinPoint;           // find the mouse cursor
            GetCursorPos(&amp;WinPoint);  // using api function, store
            SetForegroundWindow(Handle);
            PopupMenu1-&gt;Popup(WinPoint.x,WinPoint.y);
            PostMessage(Handle, WM_NULL, 0,0);
            break;
        case WM_LBUTTONDBLCLK:
            Application-&gt;Restore();
            break;
    }
}

//---------------------------------------------------------------------------
void __fastcall TForm1::UnloadBtnClick(TObject *Sender)
{
    // Terminate the app when they choose the upload option
    Application-&gt;Terminate();
}

void __fastcall TForm1::AddIcon()
{
    // Use the Shell_NotifyIcon API function to
    // add the icon to the tray.
    NOTIFYICONDATA IconData;
    IconData.cbSize = sizeof(NOTIFYICONDATA);
    IconData.uID    = IDC_TRAY1;
    IconData.hWnd   = Handle;
    IconData.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
    IconData.uCallbackMessage = WM_TRAYNOTIFY;
    lstrcpy(IconData.szTip, HINT_MESSAGE);
    IconData.hIcon  = TrayIcon-&gt;Handle;

    Shell_NotifyIcon(NIM_ADD,&amp;IconData);
}

void __fastcall TForm1::RemoveIcon()
{
    NOTIFYICONDATA IconData;
    IconData.cbSize = sizeof(NOTIFYICONDATA);
    IconData.uID    = IDC_TRAY1;
    IconData.hWnd   = Handle;
    IconData.hIcon  = TrayIcon-&gt;Handle;

    Shell_NotifyIcon(NIM_DELETE,&amp;IconData);
}

//---------------------------------------------------------------------------
void __fastcall TForm1::AppOnMinimize(TObject *Sender)
{
    ShowWindow(Application-&gt;Handle, SW_HIDE);
    Visible = false;
}

void __fastcall TForm1::AppOnRestore(TObject *Sender)
{
    ShowWindow(Application-&gt;Handle, SW_SHOW);
    Visible = true;

    SetForegroundWindow(Handle);
}

//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &amp;Key,
      TShiftState Shift)
{
 if(Key == VK_F1)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-1&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F2)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-2&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F3)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-3&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F4)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-4&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F5)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-5&quot;,&quot;Test&quot;,MB_OK);
 }
  if(Key == VK_F6)
 {
 Application-&gt;MessageBoxA(&quot;Taste F-6&quot;,&quot;Test&quot;,MB_OK);
 }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::KeyHook(TMessage &amp;Message)
{
  char Key[80];
  GetKeyNameText(Message.LParam, Key, 80);
  ListBox1-&gt;Items-&gt;Add(Key);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
SetHook();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
RemoveHook();
}
//---------------------------------------------------------------------------
</code></pre>
<p>MFG Praetorianer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/613066</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/613066</guid><dc:creator><![CDATA[Praetorianer_33]]></dc:creator><pubDate>Wed, 22 Sep 2004 17:43:23 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler aus der Hook DLL on Wed, 22 Sep 2004 18:34:48 GMT]]></title><description><![CDATA[<p>Praetorianer_33 schrieb:</p>
<blockquote>
<p>Weiß absolut nicht wo der Fehler liegt.</p>
</blockquote>
<p>Ich auch nicht. Was ist denn der Fehler? Du schreibst nur was von einer Warnung. Die Warnung<br />
ist eigentlich recht sprechend. So müsstest Du sie wegbekommen:</p>
<pre><code class="language-cpp">HOOKPROC lpfnHookProc = GetProcAddress(GetModuleHandle(&quot;keydll.dll&quot;),&quot;CheckKey&quot;);
</code></pre>
<p>Falls noch irgendwelche &quot;richtigen&quot; Fehler auftreten, solltest Du diese nochmal näher beschreiben.</p>
<p>Gruß,</p>
<p>Alexander</p>
]]></description><link>https://www.c-plusplus.net/forum/post/613139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/613139</guid><dc:creator><![CDATA[Alexander Kempf]]></dc:creator><pubDate>Wed, 22 Sep 2004 18:34:48 GMT</pubDate></item></channel></rss>