예제 #1
0
        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);
        }
예제 #2
0
        internal static int SafeStgCreateDocfileOnStream(
            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.StgCreateDocfileOnILockBytes(
                (UnsafeNativeCompoundFileMethods.UnsafeNativeILockBytes)lockByteStream,
                grfMode,
                0, // Must be zero
                out storage);

            if (result == SafeNativeCompoundFileConstants.S_OK)
            {
                ppstgOpen = new SafeIStorageImplementation(storage, lockByteStream);
            }
            else
            {
                ppstgOpen = null;
                lockByteStream.Dispose();
            }

            return(result);
        }
예제 #3
0
            internal SafeIStorageImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage,
                                                UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream lockBytesStream)
            {
                if (storage == null)
                {
                    throw new ArgumentNullException("storage");
                }

                _unsafeStorage            = storage;
                _unsafePropertySetStorage = (UnsafeNativeCompoundFileMethods.UnsafeNativeIPropertySetStorage)_unsafeStorage;
                _unsafeLockByteStream     = lockBytesStream;
            }
예제 #4
0
        internal static int SafeStgCreateDocfileOnStream(
            Stream s,
            int grfMode,
            out IStorage ppstgOpen
            )
        {
            SecurityHelper.DemandCompoundFileIOPermission();

            Invariant.Assert(s != null, "s cannot be null");

            UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage;
            UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream lockByteStream = new UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream(s);
            int result;

            result = UnsafeNativeCompoundFileMethods.StgCreateDocfileOnILockBytes(
                (UnsafeNativeCompoundFileMethods.UnsafeNativeILockBytes) lockByteStream,
                grfMode,
                0, // Must be zero
                out storage);

            if (result == SafeNativeCompoundFileConstants.S_OK)
                ppstgOpen = new SafeIStorageImplementation(storage, lockByteStream);
            else
            {
                ppstgOpen = null;
                lockByteStream.Dispose();
            }

            return result;
        }
예제 #5
0
        internal static int SafeStgOpenStorageOnStream(
            Stream s,
            int grfMode,
            out IStorage ppstgOpen
            )
        {
            SecurityHelper.DemandCompoundFileIOPermission();

            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;
           
        }