AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) hook -> variable von form1 in dll bestimmen
Thema durchsuchen
Ansicht
Themen-Optionen

hook -> variable von form1 in dll bestimmen

Ein Thema von denizli · begonnen am 27. Feb 2012 · letzter Beitrag vom 1. Mär 2012
Antwort Antwort
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.487 Beiträge
 
Delphi 12 Athens
 
#1

AW: hook -> variable von form1 in dll bestimmen

  Alt 1. Mär 2012, 11:01
Deiner DLL wird bereits ein WindowHandle übergeben, ist dieses das Handle der Form1 kannst du per SendMessage oder PostMessage komunizieren und die Variable so indirekt setzen. Eine andere Möglichkeit wäre ein Interface zu verwenden.
Delphi-Quellcode:
unit KeyboardF5;

type
  IKeyboardF5 = interface(IInterface)
    function GetF5Variable: Integer;
    procedure SetF5Variable(AValue: Integer);
  end

//---------

library jtdll;

uses
  Windows, Dialogs, Messages, KeyboardF5;

var
  HookHandle: Cardinal;
  KeyboardF5: IKeyboardF5;

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) and Assigned(KeyboardF5) then
          KeyboardF5.SetF5Variable(1);
      end;
  end;
end;

function InstallHook(AKeyboardF5: IKeyboardF5): Boolean; stdcall;
begin
  Result := (HookHandle = 0);
  if Result then
  begin
    HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0);
    KeyboardF5 := AKeyboardF5;
  end;
end;

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

exports
  InstallHook,
  UninstallHook;

end.

//---------

unit Form1;

uses
  {...}
  KeyboardF5;

type
  TForm1 = class(TForm, IKeyboardF5)
    {...}
  private
    xyz: Integer;
    function GetF5Variable: Integer;
    procedure SetF5Variable(AValue: Integer);
  end;

implementation

function TForm1.GetF5Variable: Integer;
begin
  Result := xyz;
end;

procedure TForm1.SetF5Variable(AValue: Integer);
begin
  xyz := AValue;
end;

procedure TForm1.Show(Sender: TObject);
begin
  InstallHook(Self);
end;

procedure TForm1.Close(Sender: TObject);
begin
  UnInstallHook;
end;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:11 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