Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Einfaches Hook-Beispiel (https://www.delphipraxis.net/61717-einfaches-hook-beispiel.html)

konda 25. Jan 2006 16:12


Einfaches Hook-Beispiel
 
Hallo,
Ich bin gerade dabei Hooks zu lernen. Ich verstehe zwar das Grundprinzip und schaffe es die Funktionen in einer Dll-Datei auszulagern, aber wenn ich dann die Funktionen in einer ganz normalen Anwendung anwenden will, weiß ich nicht, wie ich das machen soll. Ich hab mir schon Beispiele von Asserbad durchgelesen, aber die sind mir noch zu komplex. Deshalb, kann mir jemand ein ganz einfaches Beispiel geben? :wall:

Hier noch der Dll-Text:
Delphi-Quellcode:
library KeyboardHook;

uses
  Windows,
  Messages;

var
  HookHandle: Cardinal = 0;
  WindowHandle: Cardinal = 0;

function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
  Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
  case nCode < 0 of
    true: exit;
    false:
      begin
        //erstmal ohne bearbeitung
      end;
  end;
end;

function InstallHook(Hwnd: Cardinal): Boolean; stdcall;
begin
  Result := False;
  if HookHandle = 0 then begin
    HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0);
    WindowHandle := Hwnd;
    Result := TRUE;
  end;
end;

function UninstallHook: Boolean; stdcall;
begin
  Result := UnhookWindowsHookEx(HookHandle);
  HookHandle := 0;
end;

exports
  InstallHook,
  UninstallHook;
end.

retnyg 1. Feb 2006 00:37

Re: Einfaches Hook-Beispiel
 
Delphi-Quellcode:
function InstallHook(Hwnd: Cardinal): Boolean; stdcall; external 'KeyboardHook.dll';
function UninstallHook: Boolean; stdcall; external 'KeyboardHook.dll';

proc button1click:
if InstallHook(handle) then UninstallHook;

konda 1. Feb 2006 12:43

Re: Einfaches Hook-Beispiel
 
Danke, jetzt hab ich es das erste mal geschafft einen Hook zu setzen. :thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz