John Mott John Mott - 1 year ago 76
C# Question

From C#, how do I call Release on a returned object that implements IStorage?

I'm reading and writing Structured Storage files from C#. To open the file i call

IStorage StorageInterface;

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

This works and I can access the file. Once I call Commit() I believe I need to call Release() on the Storage object to close the file. However, I don't know how to get to Release since its implemented on IUnknown.

Can I cast StorageInterface to an object that implements IUnknown and call it that way?



Answer Source

It is derived from IUnknown. Every COM object is derived from IUnknown. Just call


Maybe I was hasty. I missed the C# part... That's how you'd do it in C++.

In C#, you should be able to call like this.


Check the's from memory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download