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

QueryGetData() private method

private QueryGetData ( Microsoft dataObject, FORMATETC &fmtetc ) : int
dataObject Microsoft
fmtetc FORMATETC
return int
        public static int QueryGetData(Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject, ref FORMATETC fmtetc)
        {
            if (dataObject == null)
                throw new ArgumentNullException("dataObject");

            int returnValue = VSConstants.E_FAIL;
            FORMATETC[] af = new FORMATETC[1];
            af[0] = fmtetc;
            try
            {
                int result = ErrorHandler.ThrowOnFailure(dataObject.QueryGetData(af));
                if(result == VSConstants.S_OK)
                {
                    fmtetc = af[0];
                    returnValue = VSConstants.S_OK;
                }
            }
            catch(COMException e)
            {
                Trace.WriteLine("COMException : " + e.Message);
                returnValue = e.ErrorCode;
            }

            return returnValue;
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Get the dropdatatype from the dataobject
        /// </summary>
        /// <param name="pDataObject">The dataobject to be analysed for its format</param>
        /// <returns>dropdatatype or none if dataobject does not contain known format</returns>
        internal static DropDataType QueryDropDataType(IOleDataObject pDataObject)
        {
            if (pDataObject == null)
            {
                return(DropDataType.None);
            }

            // known formats include File Drops (as from WindowsExplorer),
            // VSProject Reference Items and VSProject Storage Items.
            FORMATETC fmt = DragDropHelper.CreateFormatEtc(NativeMethods.CF_HDROP);

            if (DragDropHelper.QueryGetData(pDataObject, ref fmt) == VSConstants.S_OK)
            {
                return(DropDataType.Shell);
            }

            fmt.cfFormat = DragDropHelper.CF_VSREFPROJECTITEMS;
            if (DragDropHelper.QueryGetData(pDataObject, ref fmt) == VSConstants.S_OK)
            {
                // Data is from a Ref-based project.
                return(DropDataType.VsRef);
            }

            fmt.cfFormat = DragDropHelper.CF_VSSTGPROJECTITEMS;
            if (DragDropHelper.QueryGetData(pDataObject, ref fmt) == VSConstants.S_OK)
            {
                return(DropDataType.VsStg);
            }

            return(DropDataType.None);
        }