Beispiel #1
0
        public void Write(string OutputFileName)
        {
            IOleStorage OleStorage = null;

            StgCreateDocfile(OutputFileName, STGM.Direct | STGM.Create | STGM.Write | STGM.ShareExclusive, 0, out OleStorage);
            try
            {
                foreach (KeyValuePair <string, byte[]> Section in Sections)
                {
                    IOleStream OleStream = null;
                    OleStorage.CreateStream(Section.Key, STGM.Write | STGM.ShareExclusive, 0, 0, out OleStream);
                    try
                    {
                        uint Written;
                        OleStream.Write(Section.Value, (uint)Section.Value.Length, out Written);
                        OleStream.Commit(STGC.Overwrite);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(OleStream);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(OleStorage);
            }
        }
        public void Write(string OutputFileName)
        {
            IOleStorage OleStorage = null;

            StgCreateDocfile(OutputFileName, STGM.Direct | STGM.Create | STGM.Write | STGM.ShareExclusive, 0, out OleStorage);
            try
            {
                if (SolutionConfiguration.Count > 0)
                {
                    using (MemoryStream OutputStream = new MemoryStream())
                    {
                        // Write all the settings to the memory stream
                        BinaryWriter Writer = new BinaryWriter(OutputStream, Encoding.Unicode);
                        foreach (VCBinarySetting Setting in SolutionConfiguration)
                        {
                            Setting.Write(Writer);
                        }

                        // Create a named stream in the compound document and write the binary data out
                        IOleStream OleStream = null;
                        OleStorage.CreateStream("SolutionConfiguration", STGM.Write | STGM.ShareExclusive, 0, 0, out OleStream);
                        try
                        {
                            uint Written;
                            OleStream.Write(OutputStream.GetBuffer(), (uint)OutputStream.Length, out Written);
                            OleStream.Commit(STGC.Overwrite);
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(OleStream);
                        }
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(OleStorage);
            }
        }