CreateFile 返回负句柄

发布于 2024-12-13 10:16:18 字数 224 浏览 7 评论 0原文

为什么 createfile() 函数会返回 -1 的任何想法。

Handle = CreateFile(filename, &H80000000, 0, 0, 3, &H80, 0)

这要运行几次。我在想也许文件没有正确关闭?

编辑

Err.LastllError 返回 32。

Any ideas why the createfile() function would be returning -1.

Handle = CreateFile(filename, &H80000000, 0, 0, 3, &H80, 0)

This is run a few times. I was thinking perhaps maybe the file is not being closed properly?

EDIT

Err.LastllError returns 32.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染火枫林 2024-12-20 10:16:18

您关于不关闭某个地方的文件的说法可能是正确的。我首先会查看打开文件的位置,并确保有适当的错误处理例程。在错误处理程序中,我将检查“Handle”的值,如果它有效,则调用 CloseHandle(Handle)。此外,由于您要打开文件进行读访问,因此您可以将 dwShareMode 参数更改为 1,以允许后续打开同一文件进行读操作。

You are probably right about not closing the file someplace. I would start by looking where I am opening the file and making sure I have an error handling routine in place. In the error handler I would check the value of "Handle" and if it's valid call CloseHandle(Handle). Also, since you are opening the file for read access, you could change you dwShareMode parameter to 1 to allow subsequent open for read operations on the same file.

鹿港小镇 2024-12-20 10:16:18

Error 32 is ERROR_SHARING_VIOLATION (reference) which means some other process still has the file open.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文