Fehler aus der Hook DLL



  • Weiß absolut nicht wo der Fehler liegt. Wäre für eine Hilfe Dankbar.

    Erzeugen
    [C++ Warnung] dll.cpp(29): W8004 'lpfnHookProc' wurde ein Wert zugewiesen, der nie verwendet wird

    1. Code aus der dll.cpp
    [cpp]
    //---------------------------------------------------------------------------

    #include <vcl.h>
    #include <windows.h>
    #include <winuser.h>
    #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 "C" __declspec(dllexport) __stdcall void SetHook(void);
    extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
    extern "C" __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);
    //---------------------------------------------------------------------------

    void __stdcall SetHook(void)
    {
    HOOKPROC lpfnHookProc = NULL;// Fehlermeldung kommt von hier
    lpfnHookProc = GetProcAddress(GetModuleHandle("keydll.dll"),"CheckKey");
    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("TForm1", 0);
    if((nCode < 0) || nCode == HC_NOREMOVE)
    return CallNextHookEx(ghhookKB, nCode, wParam, lParam);

    // Skip if it's a repeat
    if(lParam & 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);
    }
    //---------------------------------------------------------------------------
    [/cpp]

    2. Code aus der Mainform.h

    //---------------------------------------------------------------------------
    #ifndef mainformH
    #define mainformH
    #define WM_KEYHOOK WM_USER+100 
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <Menus.hpp>
    //---------------------------------------------------------------------------
    
    #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 &Key,
              TShiftState Shift);
            void __fastcall FormCreate(TObject *Sender);
            void __fastcall FormDestroy(TObject *Sender);
    
    private:	// User declarations
        Graphics::TIcon *TrayIcon;
        void __fastcall KeyHook(TMessage &Message);
        void __fastcall WMTrayNotify(TMessage &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
    

    3. Code aus der Mainform.ccp

    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    
    const int IDC_TRAY1      = 1005;
    const char *HINT_MESSAGE = "Rechtsklick Öffnet";
    
    #include <shellapi.h>
    #include "mainform.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    
    extern "C" __declspec(dllexport) __stdcall void SetHook(void);
    extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
    extern "C" __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->Handle=LoadImage(HInstance,
                                  "LITTLEICON",
                                  IMAGE_ICON,
                                  0,0,
                                  0);
    
        // Add the icon to the taskbar
        AddIcon();
    
        Application->OnMinimize = AppOnMinimize;
        Application->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 &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(&WinPoint);  // using api function, store
                SetForegroundWindow(Handle);
                PopupMenu1->Popup(WinPoint.x,WinPoint.y);
                PostMessage(Handle, WM_NULL, 0,0);
                break;
            case WM_LBUTTONDBLCLK:
                Application->Restore();
                break;
        }
    }
    
    //---------------------------------------------------------------------------
    void __fastcall TForm1::UnloadBtnClick(TObject *Sender)
    {
        // Terminate the app when they choose the upload option
        Application->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->Handle;
    
        Shell_NotifyIcon(NIM_ADD,&IconData);
    }
    
    void __fastcall TForm1::RemoveIcon()
    {
        NOTIFYICONDATA IconData;
        IconData.cbSize = sizeof(NOTIFYICONDATA);
        IconData.uID    = IDC_TRAY1;
        IconData.hWnd   = Handle;
        IconData.hIcon  = TrayIcon->Handle;
    
        Shell_NotifyIcon(NIM_DELETE,&IconData);
    }
    
    //---------------------------------------------------------------------------
    void __fastcall TForm1::AppOnMinimize(TObject *Sender)
    {
        ShowWindow(Application->Handle, SW_HIDE);
        Visible = false;
    }
    
    void __fastcall TForm1::AppOnRestore(TObject *Sender)
    {
        ShowWindow(Application->Handle, SW_SHOW);
        Visible = true;
    
        SetForegroundWindow(Handle);
    }
    
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift)
    {
     if(Key == VK_F1)
     {
     Application->MessageBoxA("Taste F-1","Test",MB_OK);
     }
      if(Key == VK_F2)
     {
     Application->MessageBoxA("Taste F-2","Test",MB_OK);
     }
      if(Key == VK_F3)
     {
     Application->MessageBoxA("Taste F-3","Test",MB_OK);
     }
      if(Key == VK_F4)
     {
     Application->MessageBoxA("Taste F-4","Test",MB_OK);
     }
      if(Key == VK_F5)
     {
     Application->MessageBoxA("Taste F-5","Test",MB_OK);
     }
      if(Key == VK_F6)
     {
     Application->MessageBoxA("Taste F-6","Test",MB_OK);
     }
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::KeyHook(TMessage &Message)
    {
      char Key[80];
      GetKeyNameText(Message.LParam, Key, 80);
      ListBox1->Items->Add(Key);
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
    SetHook();
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm1::FormDestroy(TObject *Sender)
    {
    RemoveHook();
    }
    //---------------------------------------------------------------------------
    

    MFG Praetorianer



  • Praetorianer_33 schrieb:

    Weiß absolut nicht wo der Fehler liegt.

    Ich auch nicht. Was ist denn der Fehler? Du schreibst nur was von einer Warnung. Die Warnung
    ist eigentlich recht sprechend. So müsstest Du sie wegbekommen:

    HOOKPROC lpfnHookProc = GetProcAddress(GetModuleHandle("keydll.dll"),"CheckKey");
    

    Falls noch irgendwelche "richtigen" Fehler auftreten, solltest Du diese nochmal näher beschreiben.

    Gruß,

    Alexander


Anmelden zum Antworten