BExplorer.Shell.DropExtensions.SetDropDescription C# (CSharp) Method

SetDropDescription() public static method

public static SetDropDescription ( this dataObject, DataObject dropDescription ) : HResult
dataObject this
dropDescription DataObject
return HResult
        public static HResult SetDropDescription(this System.Runtime.InteropServices.ComTypes.IDataObject dataObject, DataObject.DropDescription dropDescription)
        {
            FORMATETC formatETC;
            FillFormatETC(DropDescriptionFormat, TYMED.TYMED_HGLOBAL, out formatETC);

            // We need to set the drop description as an HGLOBAL.
            // Allocate space ...
            IntPtr pDD = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DataObject.DropDescription)));
            try
            {
                // ... and marshal the data
                Marshal.StructureToPtr(dropDescription, pDD, false);

                // The medium wraps the HGLOBAL
                STGMEDIUM medium;
                medium.pUnkForRelease = null;
                medium.tymed = TYMED.TYMED_HGLOBAL;
                medium.unionmember = pDD;

                // Set the data
                var dataObjectCOM = dataObject;
                dataObjectCOM.SetData(ref formatETC, ref medium, true);
                return HResult.S_OK;
            }
            catch (NotImplementedException)
            {
                Marshal.FreeHGlobal(pDD);
                return HResult.S_FALSE;
            }
            catch
            {
                // If we failed, we need to free the HGLOBAL memory
                Marshal.FreeHGlobal(pDD);
                return HResult.S_FALSE;
            }
        }