B
bin2000
Unregistered / Unconfirmed
GUEST, unregistred user!
我编写了一个DLL,其中含有一个窗体,并且利用madCodeHook成功截获了windows API "sendto"函数<br>截获后我加入的代码如下:<br>function sendtoHookProc(s: TSocket; var Buf; len, flags: Integer; var addrto: TSockAddr;<br> tolen: Integer): Integer; stdcall;<br>var<br> fHwnd: THandle;<br>begin<br> <br> showmessage('获取成功!');<br>// TForm1.ListBox1.Items.Add('123');<br>//调用原API<br> result := sendtoNextHook(s, buf, len, flags, addrto, tolen);<br>end;<br>单单showmessage不会出错,但往窗体中的listbox中写入数据时就会报错。<br>这是什么原因,有办法解决吗?<br><br>窗体的原代码如下:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, madCodeHook, WinSock;<br><br><br><br>type<br> TSockaddr = packed record<br> sa_family: byte;<br> sa_data: array[0..13]of char;<br> end;<br><br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> ListBox1: TListBox;<br> procedure Button2Click(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> sendtoNextHook: function (s: TSocket; var Buf; len, flags: Integer; var addrto: TSockAddr;<br> tolen: Integer): Integer; stdcall;<br><br><br>implementation<br><br>{$R *.dfm}<br><br>function sendtoHookProc(s: TSocket; var Buf; len, flags: Integer; var addrto: TSockAddr;<br> tolen: Integer): Integer; stdcall;<br>var<br> fHwnd: THandle;<br>begin<br>// fHwnd := findwindow('Tfrm_main',nil);<br>// application.Handle := fHwnd;<br> showmessage('获取成功!'+format('%x',[application.handle]));<br>// ListBox1.Items.Add('123');<br> result := sendtoNextHook(s, buf, len, flags, addrto, tolen);<br>end;<br><br><br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> Close;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> HookAPI('ws2_32.dll', 'sendto', @sendtoHookProc, @sendtoNextHook);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> UnhookAPI(@sendtoNextHook);<br>end;<br><br>end.