The file name is the name of the file to read. The dwDesiredAccess parameter, specifying the access rights to the file, must be either zero or GENERIC_READ. The security attributes must be NULL, while the hTemplateFile parameter is ignored by Windows CE. In addition, CreateFileForMapping can only be called once on a file that is opened in GENERIC_WRITE mode.
Note Windows CE-based applications must use this function when opening files for memory-mapped use instead of using CreateFile as is used with Microsoft Windows NT or Microsoft Windows 98. The parameters for this function are similar to those for CreateFile.
Pass the name of the memory-mapped object to the process with which you want to communicate.
Call the CreateFileMapping function in the second process, using the name of the object that you passed with the first object. The name of the memory-mapped object is global. When the second process calls the CreateFileMapping function, Windows CE passes back the handle to the original object.
Use the MapViewOfFile function in either process to gain access to the memory-mapped object. A view is created by a call to MapViewOfFile to return a pointer to the memory-mapped file.
When using memory-mapped files for interprocess communication, processes should pass the name of the region to the second process, not to a pointer. The second process should create a memory-mapped object with the same name as the initial process. The name of the region is passed in CreateFileMapping. If another process opens a memory-mapped file with the same named object, Windows CE knows to pass a pointer to the same region that was opened by the first process. The system also increments a use count to track the number of opens. This assures a process that the object will remain at least until it closes the object itself.
Do not create an unnamed object and pass a memory pointer to the different processes; one process can close the unnamed object without informing the other process. To avoid this memory error, Windows CE supports naming the unnamed object. Instead of passing a pointer to the object, you can pass the name of the object. The other process then accesses the object through its name. Accessing the object through the name informs Windows CE which processes have access to the object. Windows CE then deletes the object only when both processes have closed the object.