internal static int SafeStgOpenStorageOnStream( Stream s, int grfMode, out IStorage ppstgOpen ) { Invariant.Assert(s != null, "s cannot be null"); UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage; UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream lockByteStream = new UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream(s); int result; result = UnsafeNativeCompoundFileMethods.StgOpenStorageOnILockBytes( (UnsafeNativeCompoundFileMethods.UnsafeNativeILockBytes)lockByteStream, null, grfMode, new IntPtr(0), // Pointer to SNB struct, not marshalled, must be null. 0, out storage); if (result == SafeNativeCompoundFileConstants.S_OK) { ppstgOpen = new SafeIStorageImplementation(storage); } else { ppstgOpen = null; lockByteStream.Dispose(); } return(result); }