private CoUnmarshalInterface ( IStream stm, System.Guid &riid, |
||
stm | IStream | |
riid | System.Guid | |
ppv | ||
return | int |
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); } } } }