procedure uninstallmousehook(); stdcall; begin if mymousehook.isrun then begin UnHookWindowsHookEx(mymousehook.hook); mymousehook.callbackfun :=nil; mymousehook.isrun:=not mymousehook.isrun; end; end;
Procedure DLLEntryPoint(dwReason:DWord);
begin Case dwReason of DLL_PROCESS_ATTACH:begin mymousehook.isrun:=false; end; DLL_PROCESS_DETACH:; DLL_THREAD_ATTACH:; DLL_THREAD_DETACH:; End; end;
exports installmousehook, uninstallmousehook; begin DLLProc := @DLLEntryPoint; DLLEntryPoint(DLL_PROCESS_ATTACH); end. --------------------------------------------------------------------------------
二、钩子的使用 1、调用钩子的DLL 2、安装钩子 3、一定不要忘了卸装钩子
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type Tcallbackfun=procedure(info:pchar); type TForm1 = class(TForm) memo: TMemo; Button1: TButton; procedure FormDestroy(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;