コード例 #1
0
        /// <summary>
        /// Opens the compound file storage.
        /// </summary>
        /// <param name="pwcsName">The path to the compound file to create</param>
        /// <param name="ppstg">(out) The IStorage representing this compound file</param>
        /// <returns>True indicates it opened successfully.  False indicates that the file
        /// could not be found.</returns>
        public bool OpenStorage(
            string pwcsName,
            STGM flags,
            out IStorage ppstg)
        {
            if (!ValidateCompoundFileStorage(pwcsName))
            {
                ppstg = null;
                return(false);
            }

            Ole32Storage.STGOPTIONS stgoptions = new Ole32Storage.STGOPTIONS();
            stgoptions.usVersion    = 1;
            stgoptions.ulSectorSize = 4096;

            Guid guidIStorage = typeof(IStorage).GUID;
            int  result       = Ole32Storage.StgOpenStorageEx(
                pwcsName,
                flags,
                STGFMT.STGFMT_DOCFILE,
                0,
                ref stgoptions,
                IntPtr.Zero,
                ref guidIStorage,
                out ppstg);

            if (result != HRESULT.S_OK)
            {
                Marshal.ThrowExceptionForHR(result);
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Creates the compound file storage
        /// </summary>
        /// <param name="pwcsName">The path to the compound file to create</param>
        /// <param name="ppstg">(out) The IStorage representing this compound file</param>
        public void CreateStorage(
            string pwcsName,
            out IStorage ppstg)
        {
            Ole32Storage.STGOPTIONS stgoptions = new Ole32Storage.STGOPTIONS();
            stgoptions.usVersion    = 1;
            stgoptions.ulSectorSize = 4096;

            Guid guidIStorage = typeof(IStorage).GUID;
            int  result       = Ole32Storage.StgCreateStorageEx(
                pwcsName,
                STGM.FAILIFTHERE | STGM.TRANSACTED |
                STGM.READWRITE | STGM.SHARE_DENY_WRITE,
                STGFMT.STGFMT_DOCFILE,
                0,
                ref stgoptions,
                IntPtr.Zero,
                ref guidIStorage,
                out ppstg);

            if (result != HRESULT.S_OK)
            {
                Marshal.ThrowExceptionForHR(result);
            }
        }
コード例 #3
0
        /// <summary>
        /// Opens the compound file storage.
        /// </summary>
        /// <param name="pwcsName">The path to the compound file to create</param>
        /// <param name="ppstg">(out) The IStorage representing this compound file</param>
        /// <returns>True indicates it opened successfully.  False indicates that the file
        /// could not be found.</returns>
        public bool OpenStorage(
            string pwcsName,
            STGM flags,
            out IStorage ppstg)
        {
            if (!ValidateCompoundFileStorage(pwcsName))
            {
                ppstg = null;
                return false;
            }

            Ole32Storage.STGOPTIONS stgoptions = new Ole32Storage.STGOPTIONS();
            stgoptions.usVersion = 1;
            stgoptions.ulSectorSize = 4096;

            Guid guidIStorage = typeof(IStorage).GUID;
            int result = Ole32Storage.StgOpenStorageEx(
                pwcsName,
                flags,
                STGFMT.STGFMT_DOCFILE,
                0,
                ref stgoptions,
                IntPtr.Zero,
                ref guidIStorage,
                out ppstg);

            if (result != HRESULT.S_OK)
                Marshal.ThrowExceptionForHR(result);
            return true;
        }
コード例 #4
0
        /// <summary>
        /// Creates the compound file storage
        /// </summary>
        /// <param name="pwcsName">The path to the compound file to create</param>
        /// <param name="ppstg">(out) The IStorage representing this compound file</param>
        public void CreateStorage(
            string pwcsName,
            out IStorage ppstg)
        {
            Ole32Storage.STGOPTIONS stgoptions = new Ole32Storage.STGOPTIONS();
            stgoptions.usVersion = 1;
            stgoptions.ulSectorSize = 4096;

            Guid guidIStorage = typeof(IStorage).GUID;
            int result = Ole32Storage.StgCreateStorageEx(
                pwcsName,
                STGM.FAILIFTHERE | STGM.TRANSACTED |
                STGM.READWRITE | STGM.SHARE_DENY_WRITE,
                STGFMT.STGFMT_DOCFILE,
                0,
                ref stgoptions,
                IntPtr.Zero,
                ref guidIStorage,
                out ppstg);

            if (result != HRESULT.S_OK)
                Marshal.ThrowExceptionForHR(result);
        }