首页 > 解决方案 > 共享内存 - 访问冲突

问题描述

请告诉我,我想将 json 写入共享内存。如果文本超过 2047 个字符,则 StrPCopy 错误“0x004074ba 处的访问冲突:地址条目 0x00381000”。我没有找到有关限制的信息。也许还有另一种写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;

测试用例

标签: delphidelphi-10.4-sydney

解决方案


推荐阅读