예제 #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 SafeStgOpenStorageEx(
            string pwcsName,          //Pointer to path of compound file to create
            int grfMode,              // Specifies the access mode for opening the storage object
            int stgfmt,               // Specifies the storage file format, 5 is DocFile
            int grfAttrs,             // Reserved; must be zero
            IntPtr pStgOptions,       // Pointer to STGOPTIONS, not marshalled, must use NULL.
            IntPtr reserved2,         // Reserved; must be null
            ref Guid riid,            // Specifies the GUID of the interface pointer
            out IStorage ppObjectOpen //Pointer to an interface pointer
            )
        {
            UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage;
            int result;

            result = UnsafeNativeCompoundFileMethods.StgOpenStorageEx(
                pwcsName,
                grfMode,
                stgfmt,
                grfAttrs,
                pStgOptions,
                reserved2,
                ref riid,
                out storage);

            if (result == SafeNativeCompoundFileConstants.S_OK)
            {
                ppObjectOpen = new SafeIStorageImplementation(storage);
            }
            else
            {
                ppObjectOpen = null;
            }

            return(result);
        }
예제 #3
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);
        }
예제 #4
0
 internal static int SafePropVariantClear(ref PROPVARIANT pvar)
 {
     return(UnsafeNativeCompoundFileMethods.PropVariantClear(ref pvar));
 }
예제 #5
0
 internal SafeIPropertyStorageImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIPropertyStorage propertyStorage)
 {
     _unsafePropertyStorage = propertyStorage;
 }
예제 #6
0
 internal SafeIEnumSTATPROPSETSTGImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIEnumSTATPROPSETSTG enumSTATPROPSETSTG)
 {
     _unsafeEnumSTATPROPSETSTG = enumSTATPROPSETSTG;
 }
예제 #7
0
 internal SafeIStreamImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIStream stream)
 {
     _unsafeStream = stream;
 }
예제 #8
0
            internal SafeIStorageImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage,
                                                        UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream lockBytesStream)
            {
                SecurityHelper.DemandCompoundFileIOPermission();

                if (storage == null)
                {
                    throw new ArgumentNullException("storage");
                }

                _unsafeStorage = storage;
                _unsafePropertySetStorage = (UnsafeNativeCompoundFileMethods.UnsafeNativeIPropertySetStorage) _unsafeStorage;
                _unsafeLockByteStream = lockBytesStream;
            }
예제 #9
0
 internal SafeIStorageImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage)
         : this(storage, null)
 {
 }
예제 #10
0
        // <SecurityNote>
        //     Critical:  This method calls security suppressed unmanaged CompoundFile code.
        //     ComoundFileIOPermission needs to be demanded to ensure that the only calls
        //     that can go through must be either done in Full Trust or with under assertion of
        //     CompoundFileIOPermission.
        //     SecurityTreatAsSafe:  Demands CompoundFileIOPermission before it makes any calls to
        //      unmanaged APIs
        // </SecurityNote>
        internal static int SafePropVariantClear(ref PROPVARIANT pvar)
        {
            SecurityHelper.DemandCompoundFileIOPermission();

            return(UnsafeNativeCompoundFileMethods.PropVariantClear(ref pvar));
        }