void OleInterop.IDataObject.GetDataHere(OleInterop.FORMATETC[] pFormatetc, OleInterop.STGMEDIUM[] pRemoteMedium) { if (null != oleData) { oleData.GetDataHere(pFormatetc, pRemoteMedium); return; } // Check that the arrays are not null and with only one element. if ((null == pFormatetc) || (pFormatetc.Length != 1) || (null == pRemoteMedium) || (pRemoteMedium.Length != 1)) { throw new ArgumentException(); } // Call the method on the BCL interface BclComTypes.FORMATETC bclFormat = StructConverter.OleFormatETC2Bcl(ref pFormatetc[0]); BclComTypes.STGMEDIUM bclMedium = StructConverter.OleSTGMEDIUM2Bcl(ref pRemoteMedium[0]); bclData.GetDataHere(ref bclFormat, ref bclMedium); pRemoteMedium[0] = StructConverter.BclSTGMEDIUM2Ole(ref bclMedium); }
static bool TryGetResourceValue(System.Runtime.InteropServices.ComTypes.IDataObject dataObject, string resourceName, out string value) { value = string.Empty; FORMATETC formatEtc = new FORMATETC(); formatEtc.cfFormat = (short)System.Windows.Forms.DataFormats.GetFormat(resourceName).Id; formatEtc.ptd = IntPtr.Zero; formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT; formatEtc.lindex = -1; formatEtc.tymed = TYMED.TYMED_HGLOBAL; STGMEDIUM stg = new STGMEDIUM(); stg.pUnkForRelease = null; stg.tymed = TYMED.TYMED_HGLOBAL; #pragma warning suppress 56523 stg.unionmember = SafeNativeMethods.GlobalAlloc(SafeNativeMethods.GMEM_SHARE, 255); if (stg.unionmember == IntPtr.Zero) { return(false); } try { dataObject.GetDataHere(ref formatEtc, ref stg); } catch (Exception ex) { if (Utilities.IsCriticalException(ex)) { throw; } return(false); } value = Marshal.PtrToStringUni(stg.unionmember); SafeNativeMethods.ReleaseStgMedium(ref stg); return(true); }