How to use shared memory between instances

使用共享实例内存示例,忘了出处了:

program MapDemo;
uses
Windows;
type
TShared = record
strSaveFileName: array[0..1023] of char;
end;
var
hMappingFile: THandle;
PShared: ^TShared;
Msg: TMsg;
function StrCopy(Dest: PChar; const Source: PChar): PChar;
asm
PUSH EDI
PUSH ESI
MOV ESI,EAX
MOV EDI,EDX
MOV ECX,0FFFFFFFFH
XOR AL,AL
REPNE SCASB
NOT ECX
MOV EDI,ESI
MOV ESI,EDX
MOV EDX,ECX
MOV EAX,EDI
SHR ECX,2
REP MOVSD
MOV ECX,EDX
AND ECX,3
REP MOVSB
POP ESI
POP EDI
end;
begin
hMappingFile := OpenFileMapping(FILE_MAP_READ, False, ‘test’);
if hMappingFile = 0 then
hMappingFile := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(TShared), ‘test’);
PShared := MapViewOfFile(hMappingFile, FILE_MAP_WRITE or FILE_MAP_READ, 0, 0, 0);
StrCopy(PShared^.strSaveFileName, ‘fuck bms’);
MessageBox(0, PShared^.strSaveFileName, pchar(‘It Works’), 0);
while GetMessage(Msg, 0, 0, 0) do;
UnmapViewOfFile(PShared);
CloseHandle(hMappingFile);
end.

打赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注