public void GetData(ref FORMATETC format, out STGMEDIUM medium) { ComDebug.ReportInfo("{0}.IDataObject.GetData({1})", GetType().Name, DataObjectHelper.FormatEtcToString(format)); try { // Locate the data foreach (var rendering in Renderings) { if ((rendering.format.tymed & format.tymed) > 0 && rendering.format.dwAspect == format.dwAspect && rendering.format.cfFormat == format.cfFormat && rendering.renderer != null) { // Found it. Return a copy of the data. medium = new STGMEDIUM { tymed = rendering.format.tymed & format.tymed }; medium.unionmember = rendering.renderer(medium.tymed); if (medium.tymed == TYMED.TYMED_ISTORAGE || medium.tymed == TYMED.TYMED_ISTREAM) { medium.pUnkForRelease = Marshal.GetObjectForIUnknown(medium.unionmember); } else { medium.pUnkForRelease = null; } return; } } } catch (Exception e) { ComDebug.ReportError("{0}.IDataObject.GetData threw an exception {1}", GetType().Name, e); throw; } ComDebug.ReportInfo("{0}.IDataObject.GetData, no data delivered!", GetType().Name); medium = new STGMEDIUM(); // Marshal.ThrowExceptionForHR(ComReturnValue.DV_E_FORMATETC); }
public int GetCanonicalFormatEtc(ref FORMATETC formatIn, out FORMATETC formatOut) { ComDebug.ReportInfo("{0}.IDataObject.GetCanonicalFormatEtc {1}", GetType().Name, DataObjectHelper.FormatEtcToString(formatIn)); formatOut = default(FORMATETC); return(ComReturnValue.DATA_S_SAMEFORMATETC); }
public int DAdvise(ref FORMATETC pFormatetc, ADVF advf, IAdviseSink adviseSink, out int connection) { if (null == DataAdviseHolder) { ComDebug.ReportInfo("{0}.IDataObject.DAdvise -> not implemented!", GetType().Name); connection = 0; return(ComReturnValue.E_NOTIMPL); } else { ComDebug.ReportInfo("{0}.IDataObject.DAdvise {1}, {2}", GetType().Name, DataObjectHelper.FormatEtcToString(pFormatetc), advf); try { if (pFormatetc.cfFormat != 0) // if a special format is required { int res = QueryGetData(ref pFormatetc); // ask the render helper for availability of that format if (res != ComReturnValue.S_OK) // if the required format is not available { connection = 0; // return an invalid connection cookie return(res); // and the error } } FORMATETC etc = pFormatetc; DataAdviseHolder.Advise((IDataObject)this, ref etc, advf, adviseSink, out var conn); connection = conn; return(ComReturnValue.NOERROR); } catch (Exception e) { ComDebug.ReportError("{0}.IDataObject.DAdvise exception: {1}", GetType().Name, e); throw; } } }