77 lines
2.5 KiB
Plaintext
77 lines
2.5 KiB
Plaintext
library CatchWndMsg;
|
|
|
|
{ Important note about DLL memory management: ShareMem must be the
|
|
first unit in your library's USES clause AND your project's (select
|
|
Project-View Source) USES clause if your DLL exports any procedures or
|
|
functions that pass strings as parameters or function results. This
|
|
applies to all strings passed to and from your DLL--even those that
|
|
are nested in records and classes. ShareMem is the interface unit to
|
|
the BORLNDMM.DLL shared memory manager, which must be deployed along
|
|
with your DLL. To avoid using BORLNDMM.DLL, pass string information
|
|
using PChar or ShortString parameters. }
|
|
|
|
uses
|
|
System.SysUtils,
|
|
System.Classes,
|
|
Winapi.Windows,
|
|
WindowCatchWndMsg in 'WindowCatchWndMsg.pas',
|
|
DefineWndMon in '..\DefineWndMon.pas';
|
|
|
|
{$R *.res}
|
|
|
|
var
|
|
WindowActiveHook: TWindowCatchWndMsg = nil;
|
|
|
|
procedure DLLEntryPoint(dwReason: DWORD);
|
|
begin
|
|
case dwReason of
|
|
DLL_PROCESS_ATTACH :
|
|
begin
|
|
WindowActiveHook := TWindowCatchWndMsg.Create;
|
|
end;
|
|
|
|
DLL_PROCESS_DETACH :
|
|
begin
|
|
try
|
|
if Assigned(WindowActiveHook) then
|
|
begin
|
|
{
|
|
if WindowActiveHook.SharedData.IsAvailable then
|
|
begin
|
|
|
|
case THookState(WindowActiveHook.SharedData.Data.HookState) of
|
|
hsFree :
|
|
begin
|
|
// TSunkTrace.t('WindowActiveHook >>> DLL_PROCESS_DETACH >> HookState = hsFree');
|
|
end;
|
|
hsHooking : // 이 경우는 메인에서 정식으로 DLL을 내린경우가 아니다. 다시 로드 할수 있게 한다.
|
|
begin
|
|
// TSunkTrace.t('WindowActiveHook >>> DLL_PROCESS_DETACH >> HookState = hsHooking, RcvWnd = %d', [WindowActiveHook.SharedData.Data.hRcvWnd]);
|
|
PostMessage(WindowActiveHook.SharedData.Data.hRcvWnd, WM_WNDHOOK_RELOAD, GetCurrentProcessId, GetCurrentThreadId);
|
|
end;
|
|
hsReload :
|
|
begin
|
|
// TSunkTrace.t('WindowActiveHook >>> DLL_PROCESS_DETACH >> HookState = hsReload');
|
|
end;
|
|
hsFinish : // 정상적인 DETACH 작업이라고 판단
|
|
begin
|
|
// TSunkTrace.t('WindowActiveHook >>> DLL_PROCESS_DETACH >> HookState = hsFinish');
|
|
WindowActiveHook.SharedData.Data.HookState := hsFree;
|
|
end;
|
|
end;
|
|
end;
|
|
}
|
|
FreeAndNil(WindowActiveHook);
|
|
end;
|
|
except
|
|
//
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
begin
|
|
DllProc := @DLLEntryPoint;
|
|
DLLEntryPoint(DLL_PROCESS_ATTACH);
|
|
end.
|