gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 12:38:17 26 4
gpt4 key购买 nike

我希望使用命名共享内存实现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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com