Microsoft Knowledge Base Email Alertz

(301242) - You can use a memory-mapped object to share data between processes. This article shows you how to share data between processes by using memory-mapping in Microsoft Windows CE. Requirements The following list outlines the recommended hardware,...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 301242 - Last Review: July 15, 2004 - Revision: 1.2

How To Share Memory-Mapped Objects Between Processes in Windows CE

This article was previously published under Q301242

On This Page

SUMMARY

You can use a memory-mapped object to share data between processes. This article shows you how to share data between processes by using memory-mapping in Microsoft Windows CE.

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you will need:
  • Microsoft Windows CE device
  • Microsoft Windows 2000 or Windows NT 4.0 Workstation with SP5 or later.
  • Microsoft eMbedded Visual C++ version 3.0 (formerly known as the Microsoft Windows CE Toolkit for Visual C++ version 6.0)

Sharing Data Between Processes Using Memory-Mapping

  1. Call the CreateFileMapping function to create the memory object, using the lpFileName parameter to pass in a name for the memory-mapped object:
    HANDLE CreateFileForMapping(LPCTSTR lpFileName,
          DWORD dwDesiredAccess, 
          DWORD dwShareMode, 
          LPSECURITY_ATTRIBUTES lpSecurityAttributes, 
          DWORD dwCreationDisposition, 
          DWORD dwFlagsAndAttributes,
          HANDLE hTemplateFile);
    						
    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.
  2. Pass the name of the memory-mapped object to the process with which you want to communicate.
  3. 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.
  4. 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.

Troubleshoot

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.

REFERENCES

For more information, see the Microsoft Windows CE 3.0 Software developer documentation at the following MSDN Web site:
http://msdn.microsoft.com/library/default.asp?URL=/library/wcedoc/wceintro/cestart.htm (http://msdn.microsoft.com/library/default.asp?URL=/library/wcedoc/wceintro/cestart.htm)

APPLIES TO
  • Microsoft Windows CE eMbedded Visual C++, Version:4.0 3.0
Keywords: 
kbhowto kbhowtomaster KB301242
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate