无法为我刚刚打开的文件创建文件映射,出现“找不到路径”
我正在尝试使用 CreateFileMapping() 函数(在 Windows 上)。
现在,在这段代码中:
hFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, sizeInBlocks*SO_BLOCK_SIZE, filename);
文件已正确创建,但 hFileMapping
的值为 NULL
!这很奇怪,因为我正在使用 hFile
(这是一个有效的句柄!),并且当我在调用 CreateFileMAPing()< 后检查
GetLastError()
状态时/code> 我收到ERROR_PATH_NOT_FOUND
,这很奇怪,因为另一个函数只是用它来创建文件。
有什么想法吗?
I'm trying to the CreateFileMapping()
function (on windows).
Now, in this piece of code:
hFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, sizeInBlocks*SO_BLOCK_SIZE, filename);
The file is created allright, but the value of hFileMapping
is NULL
! Which is weird because I'm using hFile
(which is a valid handle!) and when I check GetLastError()
status after the call to CreateFileMApping()
I'm getting ERROR_PATH_NOT_FOUND
, which is weird, because another function just used it to create the file.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,一直在做一些挖掘(我知道应该提前进行)。 CreateFileMapping() 的最后一个参数应该是不包含反斜杠的字符串。我使用了创建的文件路径作为该参数(以使其成为唯一的名称)。因此,返回的错误实际上应用于该参数,而不是应用于作为第一个参数传递的文件句柄。
Ok, been doing some digging (should've been beforehand, I know). The last parameter of
CreateFileMapping()
should be a string NOT containing backslashes. And I've used the filepath I've created as that parameter (to make it a unique name). So, the error returned was actually applying to that parameter and NOT to the file handle passed as the first parameter.