Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从C#,如何对实现IStorage的返回对象调用Release?_C#_Com_Iunknown_Istorage_Structured Storage - Fatal编程技术网

从C#,如何对实现IStorage的返回对象调用Release?

从C#,如何对实现IStorage的返回对象调用Release?,c#,com,iunknown,istorage,structured-storage,C#,Com,Iunknown,Istorage,Structured Storage,我正在读写C#中的结构化存储文件。打开我调用的文件 IStorage StorageInterface; int result = StgOpenStorage(filename, null, STGM.READWRITE | STGM.SHARE_EXCLUSIVE, IntPtr.Zero, 0, out StorageInterface); 这是可行的,我可以访问该文件。我认为需要对存储对象调用Release()来关闭文件。然而,我不知道如何发布,因为它是在IUnknown上实现的 我

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

IStorage StorageInterface;

int result = StgOpenStorage(filename, null, STGM.READWRITE | STGM.SHARE_EXCLUSIVE, IntPtr.Zero, 0, out StorageInterface);
这是可行的,我可以访问该文件。我认为需要对存储对象调用Release()来关闭文件。然而,我不知道如何发布,因为它是在IUnknown上实现的

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

谢谢


约翰

它是从IUnknown衍生出来的。每个COM对象都是从IUnknown派生的。就打电话

 StorageInterface->Release();
也许我太匆忙了。我错过了C部分。。。这就是你在C++中如何做的。

在C#中,您应该能够这样调用

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

检查拼写…它来自内存。

它来自IUnknown。每个COM对象都是从IUnknown派生的。就打电话

 StorageInterface->Release();
也许我太匆忙了。我错过了C部分。。。这就是你在C++中如何做的。

在C#中,您应该能够这样调用

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

检查拼写…它来自内存。

它是否继承自IDisPoble?如果没有,那么只需将Object=null,或者您可以尝试这样的方法来测试它
((IDisposable)YourObject)看起来IStorage不是从IDisposable继承的:(它是从IDisposable继承的吗?如果不是,那么只需将Object=null,或者您可以尝试这样的方法来测试它
((IDisposable)YourObject)。Dispose();
看起来IStorage不是从IDisposable继承的:(