コード例 #1
0
        public static VCSolutionOptions Read(string InputFileName)
        {
            IOleStorage Storage = null;

            StgOpenStorage(InputFileName, null, STGM.Direct | STGM.Read | STGM.ShareExclusive, IntPtr.Zero, 0, out Storage);
            try
            {
                IOleEnumSTATSTG Enumerator = null;
                Storage.EnumElements(0, IntPtr.Zero, 0, out Enumerator);
                try
                {
                    uint      Fetched;
                    STATSTG[] Stats = new STATSTG[200];
                    Enumerator.Next((uint)Stats.Length, Stats, out Fetched);

                    VCSolutionOptions Options = new VCSolutionOptions();
                    foreach (STATSTG Stat in Stats)
                    {
                        if (Stat.pwcsName == "SolutionConfiguration")
                        {
                            IOleStream OleStream;
                            Storage.OpenStream(Stat.pwcsName, IntPtr.Zero, STGM.Read | STGM.ShareExclusive, 0, out OleStream);
                            try
                            {
                                uint   SizeRead;
                                byte[] Buffer = new byte[Stat.cbSize];
                                OleStream.Read(Buffer, (uint)Stat.cbSize, out SizeRead);

                                using (MemoryStream InputStream = new MemoryStream(Buffer, false))
                                {
                                    BinaryReader Reader = new BinaryReader(InputStream, Encoding.Unicode);
                                    while (InputStream.Position < InputStream.Length)
                                    {
                                        Options.SolutionConfiguration.Add(VCBinarySetting.Read(Reader));
                                    }
                                }
                            }
                            finally
                            {
                                Marshal.ReleaseComObject(OleStream);
                            }
                        }
                    }
                    return(Options);
                }
                finally
                {
                    Marshal.ReleaseComObject(Enumerator);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(Storage);
            }
        }
コード例 #2
0
        public VCOleContainer(string InputFileName)
        {
            IOleStorage Storage = null;

            StgOpenStorage(InputFileName, null, STGM.Direct | STGM.Read | STGM.ShareExclusive, IntPtr.Zero, 0, out Storage);
            try
            {
                IOleEnumSTATSTG Enumerator = null;
                Storage.EnumElements(0, IntPtr.Zero, 0, out Enumerator);
                try
                {
                    uint      Fetched;
                    STATSTG[] Stats = new STATSTG[200];
                    Enumerator.Next((uint)Stats.Length, Stats, out Fetched);

                    for (uint Idx = 0; Idx < Fetched; Idx++)
                    {
                        IOleStream OleStream;
                        Storage.OpenStream(Stats[Idx].pwcsName, IntPtr.Zero, STGM.Read | STGM.ShareExclusive, 0, out OleStream);
                        try
                        {
                            uint   SizeRead;
                            byte[] Buffer = new byte[Stats[Idx].cbSize];
                            OleStream.Read(Buffer, (uint)Stats[Idx].cbSize, out SizeRead);
                            Sections.Add(new KeyValuePair <string, byte[]>(Stats[Idx].pwcsName, Buffer));
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(OleStream);
                        }
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(Enumerator);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(Storage);
            }
        }