在Dll中用共享内存试一下
library demo;
var
share:integer;
MemFile, demoMutex: THandle;
procedure IntoDll; stdcall;
begin
// called everytime when the dll is injected into another context
Mutex:=CreateMutex(nil,True,'demo');
MemFile:=OpenFileMapping(FILE_MAP_WRITE,False,'demo.dat');
if MemFile=0 then
MemFile:=CreateFileMapping($FFFFFFFF,nil,
PAGE_READWRITE,0,SizeOf(THookRec),'demo.dat');
share:=MapViewOfFile(MemFile,FILE_MAP_WRITE,0,0,0);
if MemFile=0 then
share:=1;
inc(share);
ReleaseMutex(HookMutex);
end;
procedure ExitDll; stdcall;
begin
try
WaitForSingleObject(demoMutex,INFINITE);
dec(share);
finally
ReleaseMutex(demoMutex);
end;
if share=0 then
begin
UnmapViewOfFile(share);
CloseHandle(MemFile);
CloseHandle(demoMutex);
end;
end;
procedure DLLEntryPoint(reason:integer);
begin
case reason of
0: {DLL_PROCESS_DETACH} ExitDll;
1: {DLL_PROCESS_ATTACH} IntoDll;
end;
end;
begin
Intodll;
DLLProc:=@DLLEntryPoint;
end.