Microsoft.VisualStudio.Project.DragDropHelper.GetSourceProjectPath C# (CSharp) Method

GetSourceProjectPath() public static method

public static GetSourceProjectPath ( Microsoft dataObject ) : string
dataObject Microsoft
return string
        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;
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Empties all the data structures added to the clipboard and flushes the clipboard.
        /// </summary>
        private void CleanAndFlushClipboard()
        {
            IOleDataObject oleDataObject = null;

            ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.OleGetClipboard(out oleDataObject));
            if (oleDataObject == null)
            {
                return;
            }


            string sourceProjectPath = DragDropHelper.GetSourceProjectPath(oleDataObject);

            if (!String.IsNullOrEmpty(sourceProjectPath) && NativeMethods.IsSamePath(sourceProjectPath, this.GetMkDocument()))
            {
                ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.OleFlushClipboard());
                int clipboardOpened = 0;
                try
                {
                    ErrorHandler.ThrowOnFailure(clipboardOpened = UnsafeNativeMethods.OpenClipboard(IntPtr.Zero));
                    ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.EmptyClipboard());
                }
                finally
                {
                    if (clipboardOpened == 1)
                    {
                        ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.CloseClipboard());
                    }
                }
            }
        }