How to use file association and pass data to a child process?

My application is running another process ("update.exe"), and I would like to transfer large data (possibly a record) from my application to the updater.

Using the command line to pass data parameters (s) is not an option, because the data is too large (also the size of the data may vary).

How to create CreateFileMapping / MapViewOfFile / UnmapViewOfFile ,
then running my update.exe,
finally Getting data in update.exe ( OpenFileMapping ),
and release of all handles (from the main application and update.exe), so I have no memory / descriptor leaks?

The code will be nice (no JCL please). C ++ is great too. Thanks.


Edit: I think my main problem is how to "signal" the main application UnmapViewOfFile and CloseHandle after update.exe to do data reading. (or maybe I need to use OpenFileMapping with bInheritHandle set to True in my child process?)
The following is an example . Example . How can a second process read data if the main process calls UnmapViewOfFile and CloseHandle ?.

+4
source share
2 answers

You can find a good example in Inter-process communication . The correct method depends on the size of your data and speed requirements.

+2
source

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.

+1
source

All Articles