c++ - 系统错误 0x5 : CreateFileMapping()

标签 c++ windows winapi windows-7 memory-mapped-files

我希望使用命名共享内存实现IPC。

为此,其中一个步骤是使用 CreateFileMapping() 获取映射内存对象的句柄。

我完全按照 MSDN 网站的建议进行操作: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();

但是,返回的句柄总是0x0,返回的系统错误代码是:0x5(拒绝访问。)

  • 只需要命名内存共享(不是文件共享)。
  • Windows 7 x64 位操作系统
  • 管理员用户权限可用
  • 开发的应用程序:64 位插件应用程序 (.dll)

有没有人有同样的经历,请问有什么办法解决吗?我使用 MSDN 站点作为我的引用,所以我不认为代码有问题。

最佳答案

看起来您没有足够的权限。

来自 MSDN:

Creating a file mapping object in the global namespace from a session other than session zero requires the SeCreateGlobalPrivilege privilege. For more information, see Kernel Object Namespaces.

...

The creation of a file-mapping object in the global namespace, by using CreateFileMapping, from a session other than session zero is a privileged operation. Because of this, an application running in an arbitrary Remote Desktop Session Host (RD Session Host) server session must have SeCreateGlobalPrivilege enabled in order to create a file-mapping object in the global namespace successfully. The privilege check is limited to the creation of file-mapping objects, and does not apply to opening existing ones. For example, if a service or the system creates a file-mapping object, any process running in any session can access that file-mapping object provided that the user has the necessary access.

关于c++ - 系统错误 0x5 : CreateFileMapping(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3999157/

相关文章:

c++ - 基于模板参数初始化静态字符

c++ - double 不能正确减去小数

C++ 工具栏和状态栏布局重叠

windows - python 3 : capture image

Windows CRYPT32 CertFreeCertificateChainEngine 从受信任的根权限中删除用户证书

winapi - 为什么 64 位可移植可执行文件的入口点地址只有 32 位?

c++ - boost::serialize: 带有位域成员变量的结构

c++ - 我不断收到错误消息,这是我第一次使用类,这是我的代码 :

c++ - 在 libc++ 上,为什么 regex_match ("tournament", regex ("tour|to|tournament")) 失败?

java - Windows 7 中的 "which java"命令返回奇怪的路径