procedure TFmClient.CreateMemMapping();
var
szMappingName: string;
begin
szMappingName := '共享内存名字';
//如果打开失败,就创建
g_MemMappingHandle := OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, PWideChar(szMappingName));
if (0 = g_MemMappingHandle) then begin
g_MemMappingHandle := CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0, 1024, PWideChar(szMappingName));
end;
if (0 = g_MemMappingHandle) then begin
DebuMsg('创建共享内存失败');
Exit;
end;
//关联地址
g_MemMapping := MapViewOfFile(g_MemMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TMemMapping));
if (not Assigned(g_MemMapping)) then begin
DebuMsg('映射共享内存失败');
Exit;
end;
//填充数据
FillChar(g_MemMapping^, SizeOf(TMemMapping), #0);
end;
procedure TFmClient.DestroyMemMapping();
begin
UnmapViewOfFile(g_MemMapping);
CloseHandle(g_MemMappingHandle);
end;