public void SetData(short dataFormat, int index, FileDescriptor descriptor) { _dataObjects.Add( new DataObject { FORMATETC = new FORMATETC { cfFormat = dataFormat, ptd = IntPtr.Zero, dwAspect = DVASPECT.DVASPECT_CONTENT, lindex = index, tymed = TYMED.TYMED_ISTREAM }, GetData = () => { // Create IStream for data var iStream = NativeMethods.CreateStreamOnHGlobal(IntPtr.Zero, true); if (descriptor.StreamContents != null) { // Wrap in a .NET-friendly Stream and call provided code to fill it using (var stream = new IStreamWrapper(iStream)) { descriptor.StreamContents(descriptor.GrfData, descriptor.FilePath, stream, descriptor.Argument); } } // Return an IntPtr for the IStream IntPtr ptr = Marshal.GetComInterfaceForObject(iStream, typeof(IStream)); Marshal.ReleaseComObject(iStream); return(new Tuple <IntPtr, int>(ptr, NativeMethods.S_OK)); }, }); }
public void SetData(short dataFormat, int index, FileDescriptor descriptor) { _dataObjects.Add( new DataObject { FORMATETC = new FORMATETC { cfFormat = dataFormat, ptd = IntPtr.Zero, dwAspect = DVASPECT.DVASPECT_CONTENT, lindex = index, tymed = TYMED.TYMED_ISTREAM }, GetData = () => { // Create IStream for data var iStream = NativeMethods.CreateStreamOnHGlobal(IntPtr.Zero, true); if (descriptor.StreamContents != null) { // Wrap in a .NET-friendly Stream and call provided code to fill it using (var stream = new IStreamWrapper(iStream)) { descriptor.StreamContents(descriptor.GrfData, descriptor.FilePath, stream, descriptor.Argument); } } // Return an IntPtr for the IStream IntPtr ptr = Marshal.GetComInterfaceForObject(iStream, typeof(IStream)); Marshal.ReleaseComObject(iStream); return new Tuple<IntPtr, int>(ptr, NativeMethods.S_OK); }, }); }