public static STGMEDIUM GetData(Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject, ref FORMATETC fmtetc) { if (dataObject == null) throw new ArgumentNullException("dataObject"); FORMATETC[] af = new FORMATETC[1]; af[0] = fmtetc; STGMEDIUM[] sm = new STGMEDIUM[1]; dataObject.GetData(af, sm); fmtetc = af[0]; return sm[0]; }
public static string GetSourceProjectPath(Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject) { string projectPath = null; FORMATETC fmtetc = CreateFormatEtc(CF_VSPROJECTCLIPDESCRIPTOR); if (QueryGetData(dataObject, ref fmtetc) == VSConstants.S_OK) { STGMEDIUM stgmedium = DragDropHelper.GetData(dataObject, ref fmtetc); if (stgmedium.tymed == (uint)TYMED.TYMED_HGLOBAL) { // We are releasing the cloned hglobal here. IntPtr dropInfoHandle = stgmedium.unionmember; if (dropInfoHandle != IntPtr.Zero) { try { string path = GetData(dropInfoHandle); // Clone the path that we can release our memory. if (!String.IsNullOrEmpty(path)) { projectPath = String.Copy(path); } } finally { Marshal.FreeHGlobal(dropInfoHandle); } } } } return(projectPath); }