System Error 0x5: CreateFileMapping()

Viewed 18938

I wish to implement IPC using Named Shared Memory.

To do this, one of the steps is getting a handle to a Mapping Memory Object, using CreateFileMapping().

I do it exactly as MSDN website reccommends: http://msdn.microsoft.com/en-us/library/aa366551(v=VS.85).aspx:

hFileMappingHandle = CreateFileMapping
    (
        INVALID_HANDLE_VALUE,      // use paging file
        NULL,                      // default security 
        PAGE_READWRITE,            // read/write access
        0,            // maximum object size (high-order DWORD) 
        256,            // maximum object size (low-order DWORD)  
        "Global\\MyFileMappingObject"          // name of mapping object
    ); 
DWORD dwError = GetLastError();

However, the handle returned is always 0x0, and the System Error Code returned is: 0x5 (Access Denied.)

  • Only Named Memory Sharing desired (not file sharing).
  • Windows 7 x64 bit OS
  • Administrator's user rights available
  • Developed Application: 64bit Plug-In application (.dll)

Does anybody have the same experience, and a way to fix it, please? I use MSDN site as my reference, so I to not think, there is problem in the code.

6 Answers

use security attributes and DACL. Example:

ZeroMemory(&attributes, sizeof(attributes));
attributes.nLength = sizeof(attributes);
ConvertStringSecurityDescriptorToSecurityDescriptorA(
            "D:P(A;OICI;GA;;;SY)(A;OICI;GA;;;BA)(A;OICI;GWGR;;;IU)",
            SDDL_REVISION_1,
            &attributes.lpSecurityDescriptor,
            NULL);
hMapObject = CreateFileMappingA(
            INVALID_HANDLE_VALUE,
            &attributes,
            PAGE_READWRITE,
            0,
            1024,
            "mySMobject");

This is a very old question and marked as answered. But going through the same MSDN article and build a sample based on it, I was able to succeed without any special privileges.

One just need to get rid of "Global\" part of the name. Surprisingly, it doens't work this way for Semaphors and Events, you will get "0x2 ERROR_FILE_NOT_FOUND". But for the memory mapped shared memory it works just fine. I was able to Create a read/write shared memory on a server, and Open it on a Client.

Related