使用StgOpenStorage以只读方式打开OLE Compound Documents [英] Opening OLE Compound Documents read-only with StgOpenStorage
问题描述
我正在XP下使用StgOpenStorage API来读取OLE复合文档,但是我找不到正确的标记组合来告诉Windows我只需要读取而不会阻塞可以通过其他任何方式访问它...
现在我正在使用STGM_READ | STGM_EXCLUSIVE
,但是很明显,如果同时尝试从另一个应用程序打开文件,它会抱怨访问被拒绝..所以我尝试了STGM_READ | STGM_SHARE_DENY_NONE
但它抱怨标志无效.
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?
提前谢谢!
(如果相关,我正在通过pythoncom从Python调用API)
(I'm calling the API from Python via pythoncom, if it's relevant)
推荐答案
这是一个猜测,但来自StgOpenStorage API文档:
This is a guess, but from the StgOpenStorage API documentation:
指定STGM_DIRECT标志时,仅以下组合之一 可以从访问和共享组中指定标志的数量
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
请注意,缺少STGM_TRANSACTED暗含了直接模式. 也就是说,如果既未指定STGM_DIRECT也未指定STGM_TRANSACTED,则STGM_DIRECT 是假定的.
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.
这表明将标志更改为
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.
这篇关于使用StgOpenStorage以只读方式打开OLE Compound Documents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!