使用 StgOpenStorage 以只读方式打开 OLE 复合文档

发布于 2024-07-26 03:30:57 字数 385 浏览 6 评论 0 原文

我在 XP 下使用 StgOpenStorage API 来读取 OLE 复合文档,但我找不到正确的标志组合来告诉 Windows 我只需读取该文件而不阻止对其的访问到任何其他进程...
现在我正在使用 STGM_READ | STGM_EXCLUSIVE 但显然,如果我同时尝试从另一个应用程序打开该文件,它会抱怨访问被拒绝。所以我尝试使用 STGM_READ | STGM_EXCLUSIVE STGM_SHARE_DENY_NONE 但它抱怨无效的标志。

有没有办法做到这一点? 我是不是走错路了?

提前致谢!

(如果相关的话,我正在通过 pythoncom 从 Python 调用 API)

I'm using the StgOpenStorage API under XP to read an OLE Compound Document, but I can't find the right mix of flags to tell Windows that I need just to read the file without blocking access to it to any other process...
Right now I'm using STGM_READ | STGM_EXCLUSIVE but obviously if at the same time I try to open the file from another application, it complains about denied access.. So I tried with STGM_READ | STGM_SHARE_DENY_NONE
but it complains about invalid flags..

Is there a way to do this? Am I going the wrong way?

Thanks in advance!

(I'm calling the API from Python via pythoncom, if it's relevant)

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

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

发布评论

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

评论(1

深海夜未眠 2024-08-02 03:30:57

这是一个猜测,但来自 StgOpenStorage API 文档:

当指定 STGM_DIRECT 标志时,仅以下组合之一
可以从访问和共享组指定标志

<前><代码>STGM_READ | STGM_SHARE_DENY_WRITE
STGM_READWRITE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE
STGM_READ | STGM_PRIORITY

请注意,缺少 STGM_TRANSACTED 意味着直接模式。
也就是说,如果既没有指定 STGM_DIRECT 也没有指定 STGM_TRANSACTED,则 STGM_DIRECT
假设。

这表明将标志更改为

STGM_READ | STGM_SHARE_DENY_NONE | STGM_TRANSACTED

应该执行您想要的操作。 这是有道理的:在“直接”模式下,如果任何人可以开始写入存储,那么他们就会覆盖我们正在读取的内容。

This is a guess, but from the StgOpenStorage API documentation:

When the STGM_DIRECT flag is specified, only one of the following combination
of flags may be specified from the access and sharing groups

STGM_READ | STGM_SHARE_DENY_WRITE
STGM_READWRITE | STGM_SHARE_EXCLUSIVE
STGM_READ | STGM_PRIORITY

Be aware that direct mode is implied by the absence of STGM_TRANSACTED.
That is, if neither STGM_DIRECT nor STGM_TRANSACTED is specified, STGM_DIRECT
is assumed.

This suggests that changing the flags to

STGM_READ | STGM_SHARE_DENY_NONE | STGM_TRANSACTED

should do what you want. This makes sense: in 'direct' mode, if anyone could start writing to the storage, then they would overwrite what we were reading.

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