コード例 #1
0
        public static void SaveObjectToStream(object obj, Stream stm)
        {
            IStreamImpl istm = new IStreamImpl(stm);

            IPersistStream ps = obj as IPersistStream;

            if (ps != null)
            {
                ps.Save(istm, false);
            }
            else
            {
                IPersistStreamInit psi = (IPersistStreamInit)obj;

                psi.Save(istm, false);
            }
        }
コード例 #2
0
        public static void LoadObjectFromStream(object obj, Stream stm)
        {
            IStreamImpl istm = new IStreamImpl(stm);

            IPersistStream ps = obj as IPersistStream;

            if (ps != null)
            {
                ps.Load(istm);
            }
            else
            {
                IPersistStreamInit psi = (IPersistStreamInit)obj;

                psi.InitNew();
                psi.Load(istm);
            }
        }
コード例 #3
0
        private void btnCreateWrite_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "All Files (*.*)|*.*";

            this.DialogResult = dlg.ShowDialog();

            if (this.DialogResult == DialogResult.OK)
            {
                try
                {
                    Stream = new IStreamImpl(dlg.FileName, System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            Close();
        }
コード例 #4
0
        private void btnCreateRead_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter        = "All Files (*.*)|*.*";
                dlg.ShowReadOnly  = false;
                this.DialogResult = dlg.ShowDialog();
                if (this.DialogResult == DialogResult.OK)
                {
                    try
                    {
                        Stream = new IStreamImpl(dlg.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            Close();
        }
コード例 #5
0
 private void btnCreateRead_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog dlg = new OpenFileDialog())
     {
         dlg.Filter = "All Files (*.*)|*.*";
         dlg.ShowReadOnly = false;
         this.DialogResult = dlg.ShowDialog();
         if (this.DialogResult == DialogResult.OK)
         {
             try
             {
                 Stream = new IStreamImpl(dlg.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     
     Close();
 }
コード例 #6
0
        private void menuObjectFromMarshalledStream_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = "All Files (*.*)|*.*";

                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        byte[] data = File.ReadAllBytes(dlg.FileName);

                        IStreamImpl stm = new IStreamImpl(new MemoryStream(data));
                        Guid        iid = COMInterfaceEntry.IID_IUnknown;
                        IntPtr      pv;

                        int hr = COMUtilities.CoUnmarshalInterface(stm, ref iid, out pv);
                        if (hr == 0)
                        {
                            object comObj = Marshal.GetObjectForIUnknown(pv);
                            Marshal.Release(pv);

                            OpenObjectInformation(comObj, "Marshalled Object");
                        }
                        else
                        {
                            Marshal.ThrowExceptionForHR(hr);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
コード例 #7
0
ファイル: COMUtilities.cs プロジェクト: tyranid/oleviewdotnet
        public static void SaveObjectToStream(object obj, Stream stm)
        {
            IStreamImpl istm = new IStreamImpl(stm);

            IPersistStream ps = obj as IPersistStream;

            if (ps != null)
            {
                ps.Save(istm, false);
            }
            else
            {
                IPersistStreamInit psi = (IPersistStreamInit)obj;

                psi.Save(istm, false);
            }
        }
コード例 #8
0
ファイル: COMUtilities.cs プロジェクト: tyranid/oleviewdotnet
        public static void LoadObjectFromStream(object obj, Stream stm)
        {
            IStreamImpl istm = new IStreamImpl(stm);

            IPersistStream ps = obj as IPersistStream;

            if (ps != null)
            {
                ps.Load(istm);
            }
            else
            {
                IPersistStreamInit psi = (IPersistStreamInit)obj;

                psi.InitNew();
                psi.Load(istm);
            }
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: tyranid/oleviewdotnet
        private void menuObjectFromMarshalledStream_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = "All Files (*.*)|*.*";

                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        byte[] data = File.ReadAllBytes(dlg.FileName);

                        IStreamImpl stm = new IStreamImpl(new MemoryStream(data));
                        Guid iid = COMInterfaceEntry.IID_IUnknown;
                        IntPtr pv;

                        int hr = COMUtilities.CoUnmarshalInterface(stm, ref iid, out pv);
                        if (hr == 0)
                        {
                            object comObj = Marshal.GetObjectForIUnknown(pv);
                            Marshal.Release(pv);

                            OpenObjectInformation(comObj, "Marshalled Object");
                        }
                        else
                        {
                            Marshal.ThrowExceptionForHR(hr);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }