2

我正在使用基于 python win32com 的 StgCreateStorageEx 调整 testStorage.py 中的代码,将我自己的 file_id 属性写入任何文件。

根据备用流(尽管不一定来自此 API 调用),应该可以保存到目录/文件夹,但更改标志会产生不同的错误,例如:

from win32com import storagecon
import pythoncom, os, win32api

fname = r"c:\temp\test\test.txt" #works
fname = r"c:\temp\test\test2"

def testit():
    m=storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE
    pss=pythoncom.StgOpenStorageEx(fname, m, storagecon.STGFMT_FILE, 0, pythoncom.IID_IPropertySetStorage)

结果是:

pywintypes.com_error: (-2147024895, '函数不正确。', 无, 无)

编辑: 关于如何在 WinXP、Win7 和 Windows Server 2003/R2 上运行的任何建议?

请注意,最终结果不一定需要使用这个 API,我只需要能够从 Python 高效地完成它。我所说的高效是指不通过许多不同的技术层。

4

2 回答 2

0

如果将 storagecon.STGM_DIRECT 添加到模式,则成功。

于 2012-08-18T00:15:12.303 回答
0

查看结果,StgOpenStorageEx 向文件添加了更多内容,而不是简单地写入 open(fname + ":stream_name"),所以我选择了它。除了无法写入标准汇总字段之外,与 StgOpenStorageEx 相比,这有什么缺点吗?

于 2012-08-18T10:08:40.947 回答