/// <summary>
        /// Determines whether the data object is capable of rendering the data described
        /// in the passed clipboard format and storage type(s). Objects attempting a
        /// paste or drop operation can call this method before calling GetData
        /// to get an indication of whether the operation may be successful
        /// </summary>
        /// <param name="clipFormat">Name of clipboard format requested</param>
        /// <param name="types">type(s) requested</param>
        /// <returns>true if the subseqent call to GetData would likely be
        /// successful, otherwise false</returns>
        public bool QueryGetData(string clipFormat, TYMED types)
        {
            // populate contents of FORMATETC structure
            FORMATETC formatEtc = new FORMATETC();

            OleDataObjectHelper.PopulateFORMATETC(clipFormat, types, ref formatEtc);

            // try to successfully query for the data
            int result = m_dataObject.QueryGetData(ref formatEtc);

            // data is available
            if (result == HRESULT.S_OK)
            {
                return(true);
            }

            // data is not available
            else if (result == DV_E.FORMATETC)
            {
                return(false);
            }

            // unexpected error
            else
            {
                Marshal.ThrowExceptionForHR(result);
                return(false); // keep compiler happy
            }
        }
        /// <summary>
        /// Extract the date from within an OleDataObject. Pass in the requested
        /// clipboard format and type (or types ORed together) that you want
        /// the data in. The method will return an OleStgMedium for the type(s)
        /// requested if it is available, otherwise it will return null.
        /// If a single type is requested then the return value can be safely
        /// cast to the requested OleStgMedium subclasss. If multiple types
        /// are requested then the return value will represent the object's
        /// preferred storage representation and client code will need to use
        /// the 'is' operator to determine what type was returned.
        /// </summary>
        /// <param name="lindex">Index of item to retreive</param>
        /// <param name="clipFormat">Name of clipboard format requested</param>
        /// <param name="types">type(s) requested</param>
        /// <returns>OleStgMedium instance if format and requested storage type
        /// are available, otherwise null</returns>
        public OleStgMedium GetData(int lindex, string clipFormat, TYMED types)
        {
            // populate contents of FORMATETC structure
            FORMATETC formatEtc = new FORMATETC();

            OleDataObjectHelper.PopulateFORMATETC(lindex, clipFormat, types, ref formatEtc);

            // attempt to get the data using the requested format
            STGMEDIUM stgMedium = new STGMEDIUM();

            if (m_dataObject != null)
            {
                int result = m_dataObject.GetData(ref formatEtc, ref stgMedium);

                // check for errors
                if (result != HRESULT.S_OK)
                {
                    // data format not supported (expected error condition)
                    if (result == DV_E.FORMATETC)
                    {
                        return(null);
                    }

                    // unexpected error condition
                    else
                    {
                        Marshal.ThrowExceptionForHR(result);
                    }
                }

                // return the correct OleStgMedium subclass depending upon the type
                switch (stgMedium.tymed)
                {
                case TYMED.NULL:
                    return(null);

                case TYMED.HGLOBAL:
                    return(new OleStgMediumHGLOBAL(stgMedium));

                case TYMED.FILE:
                    return(new OleStgMediumFILE(stgMedium));

                case TYMED.GDI:
                    return(new OleStgMediumGDI(stgMedium));

                case TYMED.MFPICT:
                    return(new OleStgMediumMFPICT(stgMedium));

                case TYMED.ENHMF:
                    return(new OleStgMediumENHMF(stgMedium));

                case TYMED.ISTREAM:
                    return(new OleStgMediumISTREAM(stgMedium));

                case TYMED.ISTORAGE:
                    return(new OleStgMediumISTORAGE(stgMedium));

                default:
                    Debug.Assert(false, "Invalid TYMED value");
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// Helper function to populate the contents of a FORMATETC structure
 /// using the passed clipboard format and type(s).
 /// </summary>
 /// <param name="clipFormat">Name of clipboard format requested</param>
 /// <param name="types">type(s) requested</param>
 /// <param name="formatEtc">FORMATETC structure to be populated</param>
 public static void PopulateFORMATETC(
     string clipFormat, TYMED types, ref FORMATETC formatEtc)
 {
     OleDataObjectHelper.PopulateFORMATETC(-1, clipFormat, types, ref formatEtc);
 }