Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
        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();
        }
        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();
        }
 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();
 }
Esempio n. 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);
                    }
                }
            }
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
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);
                    }
                }
            }
        }