Einzelnen Beitrag anzeigen

denizli

Registriert seit: 26. Dez 2010
2 Beiträge
 
#1

hook -> variable von form1 in dll bestimmen

  Alt 27. Feb 2012, 20:45
Hallo,

wie kann ich von der DLL auf die Variable von Form1 zugreifen ?

Hier der Code:

DLL
Delphi-Quellcode:
library jtdll;

uses
    Windows, Dialogs, 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
            if (wParam=VK_F5) then xyz:=1; // Hier die Zeile, die nicht funktioniert. Variable 'xyz' ist von Form1, die ich hier an der Stelle ändern möchte
        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.
Form1
Delphi-Quellcode:
var xyz: integer;

function InstallHook(AppHandle: HWND): Boolean; stdcall; external 'jtdll.dll';
function UninstallHook: Boolean; stdcall; external 'jtdll.dll';

procedure TForm1.FormCreate(Sender: TObject);
begin
    InstallHook(handle);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
    UninstallHook;
end;
LG

Geändert von denizli (27. Feb 2012 um 21:28 Uhr)
  Mit Zitat antworten Zitat