Sharing Memory-Mapped Objects Between Processes

You can use a memory-mapped object to share data between processes. However, 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 now 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.

    To share data between processes by using memory-mapping

  1. Call the CreateFileMapping function to create the memory object, using the lpName parameter to pass in a name for the memory-mapped object.
  2. Pass the name of the memory-mapped object to the process that you want to communicate with.
  3. Call CreateFileMapping 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 CreateFileMapping, Windows CE passes back the handle to the original object.

  4. Use the MapViewOfFile function in either process to gain access to the memory-mapped object.