做了个例子给你:<br>DLL:<br><br>library www;<br><br>uses<br> sharemem,<br> Windows,<br> Messages,<br> SysUtils,<br> we in 'we.pas';<br><br>{$r *.res}<br><br>exports<br> run,Stop;<br>begin<br>end.<br><br><br>unit we;<br><br><br>interface<br>uses Windows,Messages, SysUtils,TLHelp32,classes,forms;<br>var<br> HHCallWndProc:HHook;<br> OldApplication : TApplication;<br> procedure stop;stdcall;<br> procedure run(AHandle:THandle);stdcall;<br><br>implementation<br><br><br>//&sup1;&laquo;&sup1;&sup2;&sup1;&sup3;×&Oacute;&ordm;&macr;&Ecirc;&yacute;<br>procedure HookProc(OldLparam:LPARAM;uMessage:integer;wParam:WPARAM;lParam:LPARAM);stdcall;<br>var<br> ExtendStr:String;<br> SS:TSTrings;<br>begin<br> if (uMessage=WM_IME_CHAR) then<br> begin<br> Application.MessageBox('sss','ss',mb_ok);<br> end;<br>end;<br><br>//&acute;°&iquest;&Uacute;&Iuml;&ucirc;&Iuml;&cent;&sup1;&sup3;×&Oacute;&frac12;&Oslash;&raquo;&ntilde;&ordm;&ordm;×&Ouml;&Ecirc;&auml;&Egrave;&euml;<br>function CallWndProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall; <br>var <br> pcs
CWPSTRUCT;<br>begin <br> pcs:=PCWPSTRUCT(lParam);<br> if (nCode>=0) and (pcs<>nil) and (pcs^.hwnd<>0) then<br> begin<br> if (pcs^.message=WM_IME_CHAR) then<br> Application.MessageBox('sss','ss',mb_ok);<br> end; <br> Result:=CallNextHookEx(HHCallWndProc,nCode,wParam,lParam); <br>end;<br>//&AElig;&ocirc;&para;&macr;&Iacute;&pound;&Ouml;&sup1;&sup1;&sup3;×&Oacute;<br>procedure SetHook(fSet:boolean); <br>begin<br> if fSet=true then<br> begin<br> if HHCallWndProc=0 then<br> begin<br> HHCallWndProc:=SetWindowsHookEx(WH_CALLWNDPROC,@CallWndProc,hinstance,0);<br> end;<br><br> end<br> else<br> begin<br> if HHCallWndProc<>0 then<br> UnhookWindowsHookEx(HHCallWndProc);<br> end;<br>end;<br>// &Iacute;&pound;&Ouml;&sup1;<br>procedure stop;stdcall;<br>begin<br> SetHook(False);<br> Application.Handle := OldApplication.Handle;<br>end;<br>//&iquest;&ordf;&Ecirc;&frac14;<br>procedure run(AHandle:THandle);stdcall;<br>begin<br> SetHook(true);<br> OldApplication := TApplication.Create(Application);<br> OldApplication.Handle := Application.Handle;<br> Application.Handle := AHandle;<br>end;<br><br>end.<br><br>调用dLL:<br>nit Test;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TRunDll = procedure(AHandle: THandle);stdcall;<br> TStopDLL= procedure();stdcall;<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> CurDllHandle:THandle;<br><br> function RunDllFiles(DllName:String):Boolean;<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br>function TForm1.RunDllFiles(DllName:String):Boolean;<br>var<br> DllWorkPath:String;<br> RunDLL:TRunDll;<br>begin<br> result:=true;<br> DllWorkPath:='C:/Program Files/Borland/Delphi5/Projects/';<br> CurDllHandle:=LoadLibrary(pchar(DllWorkPath+DllName));<br> if CurDllHandle=0 then<br> begin<br> Application.MessageBox(pchar('&Icirc;&THORN;·¨×°&Egrave;&euml;&para;&macr;&Igrave;&not;&iquest;&acirc;'+DllName),'&frac34;&macr;&cedil;&aelig;',mb_ok+MB_ICONWARNING);<br> exit;<br> end;<br> try<br> @RunDLL:=GetProcAddress(CurDllHandle,'run');<br> if @RunDLL<>nil then<br> begin<br> try<br> RunDLL(Application.Handle);<br> except<br> result:=FALSE;<br> end;<br> end;<br> finally<br><br> end;<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> DLLFileName:String;<br>begin<br> DLLFileName:='www.dll';<br> if RunDllFiles(DLLFileName) then<br> begin<br> Application.MessageBox('&sup3;&Eacute;&sup1;&brvbar;','&Iuml;&micro;&Iacute;&sup3;&ETH;&Aring;&Iuml;&cent;',mb_ok+mb_iconinformation);<br> end<br> else<br> begin<br> Application.MessageBox('&Ecirc;§°&Uuml;','&Iuml;&micro;&Iacute;&sup3;&ETH;&Aring;&Iuml;&cent;',MB_ICONWARNING+mb_ok);<br> end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br> StopDLL:TStopDll;<br>begin<br> try<br> @StopDLL:=GetProcAddress(CurDllHandle,'stop');<br> if @StopDLL<>nil then<br> begin<br> try<br> StopDLL;<br> except<br> //result:=FALSE;<br> end;<br> end;<br> finally<br> FreeLibrary(CurDllHandle);<br> end;<br>end;<br><br>你的问题是: