private GetData ( Microsoft dataObject, FORMATETC &fmtetc ) : STGMEDIUM | ||
dataObject | Microsoft | |
fmtetc | FORMATETC | |
return | STGMEDIUM |
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); }
/// <summary> /// Retrives data from a VS format. /// </summary> public static List <string> GetDroppedFiles(ushort format, Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject, out DropDataType ddt) { ddt = DropDataType.None; List <string> droppedFiles = new List <string>(); ThreadHelper.ThrowIfNotOnUIThread(); // try HDROP FORMATETC fmtetc = CreateFormatEtc(format); 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) { ddt = DropDataType.Shell; try { uint numFiles = UnsafeNativeMethods.DragQueryFile(dropInfoHandle, 0xFFFFFFFF, null, 0); // We are a directory based project thus a projref string is placed on the clipboard. // We assign the maximum length of a projref string. // The format of a projref is : <Proj Guid>|<project rel path>|<file path> uint lenght = (uint)Guid.Empty.ToString().Length + 2 * NativeMethods.MAX_PATH + 2; char[] moniker = new char[lenght + 1]; for (uint fileIndex = 0; fileIndex < numFiles; fileIndex++) { uint queryFileLength = UnsafeNativeMethods.DragQueryFile(dropInfoHandle, fileIndex, moniker, lenght); string filename = new String(moniker, 0, (int)queryFileLength); droppedFiles.Add(filename); } } finally { Marshal.FreeHGlobal(dropInfoHandle); } } } } return(droppedFiles); }
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 && stgmedium.unionmember != IntPtr.Zero) { // We are releasing the cloned hglobal here. using (SafeGlobalAllocHandle dropInfoHandle = new SafeGlobalAllocHandle(stgmedium.unionmember, true)) { projectPath = GetData(dropInfoHandle); } } } return(projectPath); }