![]() |
hook -> variable von form1 in dll bestimmen
Hallo,
wie kann ich von der DLL auf die Variable von Form1 zugreifen ? Hier der Code: DLL
Delphi-Quellcode:
Form1
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.
Delphi-Quellcode:
LG
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; |
AW: hook -> variable von form1 in dll bestimmen
Gar nicht, da die Dll im jweiligen Adressraum des anderen Prozesses geladen wird. Da hast du keinen Zugriff mehr auf deinen Speicherbereich. -> Lösung IPC
|
AW: hook -> variable von form1 in dll bestimmen
Würde ClipBoard gehen/wäre es zu empfehlen ?
sprich: SetClipBoardData(), GetClipBoardData() Ich brauche nur eine Variable, die ich in der DLL bestimmen möchte. LG |
AW: hook -> variable von form1 in dll bestimmen
Zitat:
|
AW: hook -> variable von form1 in dll bestimmen
Abgesehn davon:
DLL und EXE haben ihre eigene RTTI und deswegen tut man überhaupt nicht grenzübergreifend (EXE<>DLL / DLL<>DLL) auf Objekte des anderen Seite zugreifen. :warn: (selbst wenn hier, wie bereits genannt, auch noch Prozessgrenze dazukommt) |
AW: hook -> variable von form1 in dll bestimmen
Wenn ich mir den JVCL Plugin-Manager anschaue, z.B. das Beispielprojekt JvPlugin - ChangingProperties, dann zeigt das doch wie so was geht.
Oder liege ich da falsch? |
AW: hook -> variable von form1 in dll bestimmen
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; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:27 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-2025 by Thomas Breitkreuz