StgOpenStorageEx .Net C#

September 19, 2010 at 12:37 PMRampidByter

Sometimes I think my attention span is consistent as a cat faced with a dot or red light on the carpet. Luckily it often leads to some very cool rabbit holes. I ended up digging into file properties on a whole new level, which are a lot more complicated than I once thought. Long story short I ended up meeting the StgOpenStorageEx function, the IPropertySetStorage, and of course the IPropertyStorage interfaces.

I spent two days of exhausting search referencing through MSDN on structs, enums, and function declarations. Countless C++, .Net code forums, and even a Delphi coding sites looking for working examples of reading file properties. Most were filled with examples that didn’t work, or were postings of unsolved errors. I ran into many errors ranging from “E_INVALIDARG” of the IPropertyStorage.ReadMultiple function to the time spent building the classes required. Turns out and most other sites all have invalid function declarations in one way or another.

All the trouble could have been saved by simply using the “Microsoft.VisualStudio.OLE.Interop” assembly to get access to the fully flushed out interfaces and required structs. Short of declaring the StgOpenStorageEx extern function the Interop assembly contains all the other required classes. The assembly can be installed with the Visual Studio SDK (2010 in my case) installer located on the Microsoft download page. I wish I had known that two days ago.

Posted in: .Net | Programming


Comments are closed