Here is a snippet of code from a memory mapped file that we use to transfer live (uncompressed) video between our applications, SecurityDescriptor is not needed, but I left it, and CreateWorldAccessDescriptor is one of our functions.
If you need to use this type of system to control messaging from services to applications or from applications that work with different user credentials, make sure that you run your file name using "Global \"
procedure TRawFeedImageQueue.CreateFileMap; var SysInfo: TSystemInfo; sd: TSecurityDescriptor; begin GetSystemInfo( SysInfo ); MapGranularity := SysInfo.dwAllocationGranularity; MapSize := sizeof( TRawFeedImageQueueData ); FSecObjOk := CreateWorldAccessDescriptor( sd, GENERIC_ALL ); FileMappingHandle := CreateFileMapping( $FFFFFFFF, @sd, PAGE_READWRITE OR SEC_COMMIT, 0, MapSize and $FFFFFFFF, PChar(FFileName) ); if FileMappingHandle <> 0 then begin MapView := MapViewOfFile( FileMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, MapSize ); end else begin MapView := nil; end; end; procedure TRawFeedImageQueue.ReleaseFileMap; begin if FileMappingHandle <> 0 then begin unMapViewOfFile( MapView ); CloseHandle( FileMappingHandle ); end; end;
Hope this helps.
Update
This code simply creates a MapView in the file of the entire file and in only one view, you can, of course, create several smaller views in one file.
Dumpsquid
source share