//下面是模拟程序<br>program Ptestdll;//调用testdll_load.dll<br>uses<br> Forms,testdllUnit1 in 'testdllUnit1.pas' {Form1};<br>{$R *.RES}<br>begin<br> Application.CreateForm(TForm1, Form1);<br> Application.Run;<br>end.<br>//===========================================<br>unit testdllUnit1;<br>interface<br>uses<br> Windows, Messages, SysUtils, Classes, Controls, StdCtrls,forms;<br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> private<br> public<br> end;<br><br> Tzj=procedure;stdcall;<br><br>var<br> Form1: TForm1;<br> hDll:HMODULE;<br> myzj:Tzj;<br>implementation<br>{$R *.DFM}<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> hDll:=loadlibrary('testdll_load.dll');<br> @myzj:=GetProcAddress(hDll,'zj');<br> myzj;<br> FreeLibrary(hDll);<br>end;<br><br>end.<br><br>//===========================================<br>//我不能在DLL里面接收消息<br>library testdll_load;//替换testdll<br>uses<br> windows,messages;<br>type<br> Tzj=procedure;stdcall;<br>var<br> hDll:HMODULE;<br> myzj:Tzj;<br> a:integer;<br> ht:integer;<br> one:boolean;<br> hW:integer;<br> Msg:TMsg;<br> wClass:TWndClass;<br> ThreadId2
WORD;<br><br>procedure TimeProc;<br>begin<br> messagebeep(0);//这里根本就不进入!!<br>end;<br><br>//只能收到36,129,131,1消息,以后就再也收不到了<br>function WindowProc(hWnd,Msg,wParam,lParam:longint):LRESULT; stdcall;<br>begin<br> Result:=DefWindowProc(hWnd,Msg,wParam,lParam);<br> case Msg of<br> 1:begin<br> ht:=SetTimer(hW,0,500,@TimeProc);<br> end;<br> wm_destroy:<br> begin<br> halt;<br> end;<br> end;<br>end;<br><br>procedure run;stdcall;<br>begin<br> wClass.lpfnWndProc:=@WindowProc;<br> wClass.hInstance:=hInstance;<br> wClass.lpszClassName:=' ';<br> RegisterClass(wClass);<br> hw:=CreateWindowEx(0,' ',' ',0,0,0,0,0,0,0,hInstance,nil);<br> while(GetMessage(Msg,hW,0,0))do begin<br> TranslateMessage(Msg);<br> DispatchMessage(Msg);<br> end;<br>end;<br><br>procedure doMyHideProc;<br>begin<br> if ht=0 then begin<br> run;<br> end;<br>end;<br><br>procedure zj;stdcall;<br>begin<br> CreateThread(nil,0,@doMyHideProc,nil,0,ThreadId2);<br> hDll:=loadlibrary('testdll.dll');<br> @myzj:=GetProcAddress(hDll,'zj');<br> myzj;<br> FreeLibrary(hDll);<br>end;<br><br>exports<br> zj index 0;<br><br>begin<br> ht:=0;<br>end.<br>//===========================================<br>library testdll;//原始dll,被testdll_load替换<br>uses windows;<br><br>procedure zj;stdcall;<br>begin<br> messagebox(0,'我在这里','zj',0);<br>end;<br><br>exports<br> zj index 0;<br><br>end.<br>