1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| hSharedMemory := CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0, SizeOf(ShortString), nil);
procedure Write(const Value :string);
var
Data :PShortString;
begin
WaitForSingleObject(hMutex, INFINITE);
try
Data := MapViewOfFile(hSharedMemory, FILE_MAP_WRITE, 0, 0, SizeOf(ShortString));
if not Assigned(Data) then
RaiseLastOSError;
Data^ := Value;
UnMapViewOfFile(Data);
finally
ReleaseMutex(hMutex);
end;
end;
function Read :string;
var
Data :PShortString;
begin
WaitForSingleObject(hMutex, INFINITE);
try
Data := MapViewOfFile(hSharedMemory, FILE_MAP_READ, 0, 0, SizeOf(ShortString));
if not Assigned(Data) then
RaiseLastOSError;
Result := Data^;
UnMapViewOfFile(Data);
finally
ReleaseMutex(hMutex);
end;
end; |
Partager