给你个以前写的完整的程序。<br>library Project2;<br><br>{ MouseHook.Dll }<br><br>uses<br> SysUtils,<br> Windows,<br> Messages,Dialogs,<br> Classes;<br><br>var<br> HookProc: HHook;<br>function SetHook(nCode: Integer;wParam: WPARAM;lParam: LPARAM):LRESULT;stdcall;<br>begin<br> result := 0 ;<br> if nCode < 0 then<br> begin<br> result := CallNextHookEx(HookProc, nCode, wParam, lParam);<br> exit;<br> end;<br> if wParam = WM_RBUTTONUP then<br> begin<br> ShowMessage('Can not run this program!');<br> result := 1;<br> end;<br>end;<br>function InstallHook(AHandle: THandle):Boolean;<br>var<br> id: DWord;<br>begin<br> result := false;<br> id := GetWindowThreadProcessID(AHandle, nil);<br> HookProc := SetWindowsHookEx(WH_MOUSE, SetHook, HInstance, id);<br> result := HookProc <> 0;<br>end;<br>function UnInstallHook:Boolean;<br>begin<br> if HookProc <> 0 then<br> begin<br> UnHookWindowsHookEx(HookProc);<br> HookProc := 0;<br> end;<br> result := HookProc = 0;<br>end;<br>exports InstallHook, UnInstallHook;<br>begin<br> HookProc := 0;<br>end.<br>/////////////////////////////////////////////////////////////<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> DllHandle: THandle;<br> InstallHook: function (AHandle: THandle):Boolean;<br> UnInstallHook: function :Boolean;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> AHandle: THandle;<br>begin<br> AHandle := FindWindow('progman',nil);<br> if InstallHook(AHandle) then<br> ShowMessage('Hook Installed successfully on ' + IntToStr(AHandle));<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> DllHandle := LoadLibrary('Project2.dll');<br> InstallHook := GetProcAddress(DllHandle, 'InstallHook');<br> UnInstallHook := GetProcAddress(DllHandle, 'UnInstallHook');<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> if UnInstallHook then<br> ShowMessage('hook has been uninstalled successfully!');<br>end;<br><br>end.