Primary Interop Assembly for IStorage (ole32)
-
Monday, September 11, 2006 9:03 AM
Hi is there an "official" PIA for IStorage? Given that its used all over VSTO, I looked in there, couldnt find anything relevant (or did I miss something?)
(More specifically, I'm looking for a handy little wrapper class to use in C# - my C++ is well rusty)
TIA
All Replies
-
Monday, September 11, 2006 2:10 PMModeratorAre you sure about that? I couldn't find IStorage anywhere in the Microsoft.Office.Tools.* assemblies. Can you give us an example?
-
Monday, September 11, 2006 3:34 PM
Sorry should have been clearer - I couldnt find any reference to it, but the interface is used extensively in Word, Outlook, excel etc to save the office documents in structured storage - thats why I looked in VSTO.
The only documentation I can find is aimed at C++ - theres nothing for C#.
In fact, I'm a numpty - ole32 is not a COM dll, so you cant create a PIA for it..!
What I'm looking for is a handy little utility class that will allow me to open a structured storage file (Using StgOpenStorageEx) or create one (using StgCreateStorageEx) and allow me to enumerate the streams, write to them etc. I've googled, and a number of folk have asked the question, but theres very little sample code detailing the marshalling required.
-
Monday, April 30, 2007 1:25 PM
The IStorage interface is documented on MSDN and the .Net implimentation of is can be found in the namespace Microsoft.VisualStudio.Ole.Interop. I've done a couple implimentation of the IStorage and IPropSetStorage interfaces in C# specifically for reading textual data embeded documents and files as well as extended properties for the purposes of search engine indexing.
An example IStorage interface might look something like this in C#:
Code Snippet[
ComImport,SuppressUnmanagedCodeSecurity,
Guid( "0000000B-0000-0000-C000-000000000046" ),
InterfaceType( ComInterfaceType.InterfaceIsIUnknown )]
public interface IStorage{
[
return: MarshalAs( UnmanagedType.Interface )] UCOMIStream CreateStream( [In, MarshalAs( UnmanagedType.BStr )] string pwcsName,[In, MarshalAs( UnmanagedType.U4 )] int grfMode,
[In, MarshalAs( UnmanagedType.U4 )] int reserved1,
[In, MarshalAs( UnmanagedType.U4 )] int reserved2 );
[return: MarshalAs( UnmanagedType.Interface )]
UCOMIStream OpenStream( [In, MarshalAs( UnmanagedType.BStr )] string pwcsName,
IntPtr reserved1,
[In, MarshalAs( UnmanagedType.U4 )] int grfMode,
[In, MarshalAs( UnmanagedType.U4 )] int reserved2 );
[return: MarshalAs( UnmanagedType.Interface )]
IStorage CreateStorage( [In, MarshalAs( UnmanagedType.BStr )] string pwcsName,
[In, MarshalAs( UnmanagedType.U4 )] int grfMode,
[In, MarshalAs( UnmanagedType.U4 )] int reserved1,
[In, MarshalAs( UnmanagedType.U4 )] int reserved2 );
[return: MarshalAs( UnmanagedType.Interface )]
IStorage OpenStorage( [In, MarshalAs( UnmanagedType.BStr )] string pwcsName,
IntPtr pstgPriority, [In, MarshalAs( UnmanagedType.U4 )] int grfMode,
IntPtr snbExclude, [In, MarshalAs( UnmanagedType.U4 )] int reserved );
void CopyTo( int ciidExclude,
[In, MarshalAs( UnmanagedType.LPArray )] Guid[] rgiidExclude,
IntPtr snbExclude,
[In, MarshalAs( UnmanagedType.Interface )] IStorage pstgDest );
void MoveElementTo( [In, MarshalAs( UnmanagedType.BStr )] string pwcsName,
[In, MarshalAs( UnmanagedType.Interface )] IStorage pstgDest,
[In, MarshalAs( UnmanagedType.BStr )] string pwcsNewName,
[In, MarshalAs( UnmanagedType.U4 )] int grfFlags );
void Commit( int grfCommitFlags );
void Revert();
int EnumElements( [In, MarshalAs( UnmanagedType.U4 )] int reserved1,
IntPtr reserved2, [In, MarshalAs( UnmanagedType.U4 )] int reserved3,
[MarshalAs( UnmanagedType.Interface )] out IEnumSTATSTG ppenum );
void DestroyElement( [In, MarshalAs( UnmanagedType.BStr )] string pwcsName );
void RenameElement( [In, MarshalAs( UnmanagedType.BStr )] string pwcsOldName,
[In, MarshalAs( UnmanagedType.BStr )] string pwcsNewName );
void SetElementTimes( [In, MarshalAs( UnmanagedType.BStr )] string pwcsName,
[In] System.Runtime.InteropServices.ComTypes.FILETIME pctime,
[In] System.Runtime.InteropServices.ComTypes.FILETIME patime,
[In] System.Runtime.InteropServices.ComTypes.FILETIME pmtime );
void SetClass( ref Guid clsid );
void SetStateBits( int grfStateBits, int grfMask );
int Stat( out System.Runtime.InteropServices.ComTypes.STATSTG pStatStg,
int grfStatFlag );
}
-
Wednesday, March 31, 2010 4:35 PM
Are you stil havein difficulty with this? If so, can you please post more about it?
"There's a way to do it better - find it." - Thomas Edison

