Opening OLE Compound Documents read-only with StgOpenStorage

流过昼夜 提交于 2019-12-11 06:37:08

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/1086814/opening-ole-compound-documents-read-only-with-stgopenstorage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!