function GetMsgProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
begin
Result:=(CallNextHookEx(hHk,nCode,wParam,lParam));//什么都不需要做
end;
function DllEntryPoint(fdwReason:DWORD):boolean;
var
szFileName:array[0..255] of Char;
begin
if fdwReason=DLL_PROCESS_ATTACH then
begin
GetModuleFileName(0,szFileName,256);
if pos(szFileName,'delphi32.exe')>0then
SendMessageA(hws,WM_COPYDATA,0,0);
end
end;
function hookoff():boolean;stdcall;
begin
UnhookWindowsHookEx(hhk);
end;
exports hookoff;
function HookOn(Hwnds:HWND):longint;stdcall;
begin
hws:=Hwnds;
hhk :=SetWindowsHookEx(WH_GETMESSAGE,@GetMsgProc,hInstance,0);
result:=hws;
end;
exports Hookon;
begin
DllProc:=@DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
const
MFileName='ShareData';
type
TShared=record
hws:longint;
end;
PShared=^TShared;
var
hHk:HHOOK;
Shared : PShared;
MemFile:THandle;
{$R *.res}
function GetMsgProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;
begin
Result:=(CallNextHookEx(hHk,nCode,wParam,lParam));//什么都不需要做
end;
procedure Extro;
begin
UnmapViewOfFile(Shared);
CloseHandle(MemFile);
end;
procedure DllEntryPoint(fdwReason:DWORD);
var
szFileName:array[0..255] of Char;
begin
if fdwReason=DLL_PROCESS_ATTACH then
begin
GetModuleFileName(0,szFileName,256);
if pos(szFileName,'delphi32.exe')>0then
SendMessage(Shared^.hws,WM_USER+102,0,0);
end;
Extro;
end;
function hookoff():boolean;stdcall;
begin
UnhookWindowsHookEx(hhk);
Etro;
end;
exports hookoff;
function HookOn(Hwnds:HWND):longint;stdcall;
begin
Shared^.hws:=Hwnds;
hhk :=SetWindowsHookEx(WH_GETMESSAGE,@GetMsgProc,hInstance,0);
result:=Shared^.hws;
end;
exports Hookon;
begin
MemFile:=OpenFileMapping(FILE_MAP_ALL_ACCESS,false,MFileName);
if MemFile=0 then
begin
MemFile:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(TShared),MFileName);
Shared:=MapViewOfFile(MemFile,FILE_MAP_WRITE,0,0,0);
end;
Shared:=MapViewOfFile(MemFile,FILE_MAP_WRITE,0,0,0);