FAQ TAsten HOOK



  • Hallo ich hatte das Bsp aus dem FAQ mit dem wltweiten abfangen von Tasten (Hook) ausprobiert das Problem besteht aber das der Linker meldet:

    [ILINK32 Fehler] Error: Nicht aufl÷sbares externes 'SetHook' referenziert von C:\DOKUMENTE UND EINSTELLUNGEN\USER\DESKTOP\KEYHOOK DLL\DEBUG\UNIT1.OBJ
    [ILINK32 Fehler] Error: Nicht aufl÷sbares externes 'RemoveHook' referenziert von C:\DOKUMENTE UND EINSTELLUNGEN\USER\DESKTOP\KEYHOOK DLL\DEBUG\UNIT1.OBJ

    Habe aber alles so gemacht wie in der Beschreibung steht. Wäre für eine gängige Antwort dankbar.



  • die gängige Antwort in dem Fall: zeig mal deinen Code.

    greetz KN4CK3R



  • Code: dll.cpp

    //--------------------------------------------------------------------------- 
    
    #include <vcl.h> 
    #include <windows.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; 
      lpfnHookProc = GetProcAddress(GetModuleHandle("keyhook.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("TKeyHookForm", 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); 
    } 
    //---------------------------------------------------------------------------
    

    Code: Header Form.h

    //--------------------------------------------------------------------------- 
    
    #ifndef Unit1H 
    #define Unit1H 
    #define WM_KEYHOOK WM_USER+100 
    //--------------------------------------------------------------------------- 
    #include <Classes.hpp> 
    #include <Controls.hpp> 
    #include <StdCtrls.hpp> 
    #include <Forms.hpp> 
    //---------------------------------------------------------------------------
    class TKeyHookForm : public TForm 
    { 
    __published:    // Von der IDE verwaltete Komponenten 
    	TListBox *ListBox1;
            void __fastcall FormCreate(TObject *Sender); 
            void __fastcall FormDestroy(TObject *Sender); 
    private: // User declarations 
      MESSAGE void __fastcall KeyHook(TMessage &Message); 
        BEGIN_MESSAGE_MAP 
          MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook); 
        END_MESSAGE_MAP(TForm); 
    public:     // Anwender-Deklarationen 
            __fastcall TKeyHookForm(TComponent* Owner); 
    }; 
    //--------------------------------------------------------------------------- 
    extern PACKAGE TKeyHookForm *KeyHookForm; 
    //--------------------------------------------------------------------------- 
    #endif
    

    Code: Form.cpp

    //--------------------------------------------------------------------------- 
    
    #include <vcl.h>
    #pragma hdrstop 
    
    #include "Unit1.h" 
    //--------------------------------------------------------------------------- 
    #pragma package(smart_init) 
    #pragma resource "*.dfm" 
    TKeyHookForm *KeyHookForm; 
    
    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 TKeyHookForm::TKeyHookForm(TComponent* Owner) 
      : TForm(Owner) 
    { 
    } 
    //--------------------------------------------------------------------------- 
    void __fastcall TKeyHookForm::KeyHook(TMessage &Message) 
    { 
      char Key[80]; 
      GetKeyNameText(Message.LParam, Key, 80); 
      ListBox1->Items->Add(Key); 
    } 
    //--------------------------------------------------------------------------- 
    void __fastcall TKeyHookForm::FormCreate(TObject *Sender) 
    { 
      SetHook();
    } 
    //--------------------------------------------------------------------------- 
    void __fastcall TKeyHookForm::FormDestroy(TObject *Sender) 
    { 
      RemoveHook();
    } 
    //---------------------------------------------------------------------------
    


  • du musst noch die *.lib deiner DLL mit ins Programm einbinden.

    greetz KN4CK3R



  • OKI habs versucht mit der lib habe auch dll paar mal neu erstellt funktioniert immer noch net . Na egal sollte es net so sein werde mich erst mal weiter um den Rest kümmern .

    Besten Dank




Log in to reply