unit DAssistHookMain; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls; type TInstallWindowActiveHook = function: Integer; stdcall;//function(sShareMapFilename: PChar): Integer; stdcall; TUninstallWindowActiveHook = function: Integer; stdcall; TDlgAssistHookMain = class(TForm) tCheckMutex: TTimer; procedure tCheckMutexTimer(Sender: TObject); private { Private declarations } hHookDLL_: THandle; public { Public declarations } Constructor Create(aOwner: TComponent); override; Destructor Destroy; override; end; var DlgAssistHookMain: TDlgAssistHookMain; implementation uses Define, Tocsg.Win32; {$R *.dfm} Constructor TDlgAssistHookMain.Create(aOwner: TComponent); procedure LoadHookDLL; var hUser32: THandle; sPath: String; fnInstallWindowActiveHook: TInstallWindowActiveHook; begin sPath := ExtractFilePath(Application.ExeName) + gParam.HookDllName; if FileExists(sPath) then begin hHookDLL_ := LoadLibrary(PChar(sPath)); if hHookDLL_ > 0 then begin fnInstallWindowActiveHook := nil; @fnInstallWindowActiveHook := GetProcAddress(hHookDLL_, 'InstallWindowActiveHook'); if @fnInstallWindowActiveHook <> nil then {$IFDEF DEBUG} ASSERT(fnInstallWindowActiveHook = 0); {$ELSE} fnInstallWindowActiveHook; {$ENDIF} end; end; end; begin Inherited Create(aOwner); if MutexExists(gParam.WatchMutex) then LoadHookDLL; tCheckMutex.Enabled := true; end; Destructor TDlgAssistHookMain.Destroy; var fnUnInstallWindowActiveHook: TUninstallWindowActiveHook; begin if hHookDLL_ > 0 then begin @fnUnInstallWindowActiveHook := nil; @fnUnInstallWindowActiveHook := GetProcAddress(hHookDLL_, 'UnInstallWindowActiveHook'); if @fnUnInstallWindowActiveHook <> nil then fnUnInstallWindowActiveHook; FreeLibrary(hHookDLL_); hHookDLL_ := 0; end; Inherited; end; procedure TDlgAssistHookMain.tCheckMutexTimer(Sender: TObject); begin if not MutexExists(gParam.WatchMutex) then Close; // TerminateProcess(GetCurrentProcess, 0); end; end.