Einzelnen Beitrag anzeigen

Chris P

Registriert seit: 8. Mär 2004
230 Beiträge
 
Delphi 7 Enterprise
 
#1

Frage bzgl. HookHandle und DLL

  Alt 28. Feb 2007, 09:56
Hi Leute,

ich habe folgende Frage zu einem HookHandle und einer DLL:

Man hat ein Hauptprogramm und eine DLL in der ein Keyboardhook implementiert ist.

Nun wird ja aus dem Hauptprogramm heraus der Hook installiert mittels SetWindowsHook(...)
Der Rückgabewert ist das HookHandle. Also wird ja das Handle nur in der DLL-Kopie des
Hauptprogramms gesetzt.

Jetzt greift aber CallNextHookEx(...) in der Hook-Proc auf das Handle zu.
Wenn dies nun von einer anderen DLL-Kopie erfolgt ist das Handle ja immer 0, da es eine globale
Variable ist.

Wie funktioniert es dann, dass der nächste Hook korrekt ausgeführt wird?

Hier nochmal der Quelltext aus der DLL:
Delphi-Quellcode:
var
  hHook: LongWord = 0; // <--- globales HookHandle

function HookProc(Code: Integer; wParam: LongWord; lParam: LongWord): LongWord; stdcall;
begin
  Result := CallNextHookEx(hHook, Code, wParam, lParam);

  [...]
end;

function SetHook(): Boolean; stdcall;
begin
  if ( hHook = 0 ) then
  begin
    // HookHandle wird nur von Hauptprogramm gesetzt
    hHook := SetWindowsHookEx(WH_KEYBOARD, @HookProc, hInstance, 0);
  end;
  Result := hHook <> 0;
end;
Danke schonmal im Voraus...
  Mit Zitat antworten Zitat