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 uallcollection hook (https://www.delphipraxis.net/139659-uallcollection-hook.html)

ghost007 2. Sep 2009 12:26


uallcollection hook
 
Hi,
ich versuche mich gerade zum erstenmal an einem hook. Hierfür benutzte ich die uallcollection.
Mein code sieht momentan so aus:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, uallHook;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

var
  origMoveWindow: procedure (x: UINT;y: UINT; nWidth: UINT;nHeight: UINT;bRepaint: boolean); stdcall;
  newMoveWindow: procedure (x: UINT;y: UINT; nWidth: UINT;nHeight: UINT;bRepaint: boolean); stdcall;

implementation

{$R *.dfm}

procedure callback(x: UINT;y: UINT; nWidth: UINT;nHeight: UINT;bRepaint: boolean); stdcall;
begin
  ShowMessage(IntToStr(x)+'|'+IntToStr(y)+'|'+IntToStr(nWidth)+'|'+IntToStr(nHeight));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  @origMoveWindow:=GetProcAddress(LoadLibrary('user32.dll'),'MoveWindow');

  uallHook.HookCode(@origMoveWindow,@callback,@newMoveWindow);
  MoveWindow(self.Handle,1,1,500,500,true); //hier

  uallHook.UnhookCode(@newMoveWindow);
end;

end.
Dieser funktioniert soweit auch ganz toll, ich bekomm die messagebox angezeigt mit den werten etc. jedoch bekomm ich nach der markierten zeile(sprich nachdem die messagebox weggeklickt wurde) eine AV.

Was mach ich falsch?


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

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