/// <summary>Opens a compound document file and represents it as an IStorage object</summary>
/// <remarks>Use on Windows 2000 and earlier</remarks>
/// <param name="pwcsName">The path and filename of the file to open</param>
/// <param name="pstgPriority">Generally passed as null</param>
/// <param name="grfMode">Access Method</param>
/// <param name="snbExclude">Must be NULL</param>
/// <param name="reserved">Pass as zero (0)</param>
/// <param name="ppstgOpen">out IStorage</param>
/// <returns>int HRESULT</returns>
/// Needs more help form MS
[DllImport("ole32.dll")]
static extern int StgOpenStorage(
[MarshalAs(UnmanagedType.LPWStr)] string pwcsName
, IStorage pstgPriority
, STGM grfMode // Access Method (uint)
, IntPtr snbExclude // Must be NULL
, uint reserved // Reserved
, out IStorage ppstgOpen); // Returned Storage
///PreserveSig set to false automatically converts HRESULTS values to exceptions.
///Note the return value is void not an int (HRESULT).
[DllImport("ole32.dll", PreserveSig = false)]
static extern void StgOpenStorage([MarshalAs(UnmanagedType.LPWStr)] string pwcsName,
IStorage pstgPriority, STGM grfMode, IntPtr snbExclude, uint reserved,
out IStorage ppstgOpen);
None.
Win2K and later should use the StgOpenStorageEx function.
Please add some!
string pathAndFilename = @"C:\outlookmail.msg"
IStorage storage;
int hResult = StgOpenStorage(pathAndFilename, null, STGM.READ_ONLY, IntPtr.Zero, 0, out storage);
// Then one can use the EnumElements method of the IStorage interface to enum the properties of the OLE2 storage.
See StgOpenStorageEx for an example of using the System.IO.Packaging classes to access OLE structured storage.