0

我正在从 C# 读取和写入结构化存储文件。打开我调用的文件

IStorage StorageInterface;

int result = StgOpenStorage(filename, null, STGM.READWRITE | STGM.SHARE_EXCLUSIVE, IntPtr.Zero, 0, out StorageInterface);

这有效,我可以访问该文件。我相信我需要在 Storage 对象上调用 Release() 来关闭文件。但是,自从在 IUnknown 上实施以来,我不知道如何到达 Release。

我可以将 StorageInterface 转换为实现 IUnknown 的对象并以这种方式调用它吗?

谢谢,

约翰

4

1 回答 1

4

它源自 IUnknown。每个 COM 对象都派生自 IUnknown。打电话

 StorageInterface->Release();

也许我很仓促。我错过了 C# 部分......这就是你在 C++ 中的做法。

在 C# 中,您应该可以这样调用。

System.Runtime.InteropServices.Marshal.ReleaseComObject(StorageInterface);

检查拼写......它来自记忆。

于 2016-10-18T00:14:06.933 回答