Please tell me, I want to write json to shared memory. StrPCopy if the text is more than 2047 character error "Access violation at 0x004074ba: address entry 0x00381000". I did not find information about the restrictions. Maybe there is another way to write json?
var
SecurityAttr: TSecurityAttributes;
SecurityDescr: TSecurityDescriptor;
begin
InitializeSecurityDescriptor(@SecurityDescr,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(@SecurityDescr,True,nil,False);
SecurityAttr.nLength:=SizeOf(TSecurityAttributes);
SecurityAttr.lpSecurityDescriptor:=@SecurityDescr;
SecurityAttr.bInheritHandle:=True;
SendMMF := CreateFileMapping($FFFFFFFF, @SecurityAttr, PAGE_READWRITE, 0, 32,PChar('Global\Test'));
if (SendMMF = 0) then
Exit;
SendData := MapViewOfFile(SendMMF, FILE_MAP_WRITE, 0, 0, 0);
if SendData = nil then
Exit;
StrPCopy(SendData, GetJson);
if Assigned(SendData) then
Exit;
if SendMMF.Size > 0 then
Exit;
UnmapViewOfFile(SendData);
SendData := nil;
CloseHandle(SendMMF);
end;
$FFFFFFFF
for thehFile
parameter will work in a 32bit build, but not in a 64bit build, you would need to use$FFFFFFFFFFFFFFFF
instead. Better to use the existingINVALID_HANDLE_VALUE
constant instead, like the documentation says to use. It has the correct value in both builds. – Remy Lebeau Jan 27 at 15:49if Assigned(SendData) then Exit;
, it is causing you to leak the MMF and its view. Also,if SendMMF.Size > 0 then
should not even compile, since aTHandle
doesn't have aSize
member. – Remy Lebeau Jan 27 at 15:51