BExplorer.Shell.DataObject.SetData C# (CSharp) Method

SetData() public method

Sets data in the specified format into storage.
public SetData ( System.Runtime.InteropServices.ComTypes.FORMATETC &formatIn, System.Runtime.InteropServices.ComTypes.STGMEDIUM &medium, bool release ) : void
formatIn System.Runtime.InteropServices.ComTypes.FORMATETC The format of the data.
medium System.Runtime.InteropServices.ComTypes.STGMEDIUM The data.
release bool If true, ownership of the medium's memory will be transferred /// to this object. If false, a copy of the medium will be created and maintained, and /// the caller is responsible for the memory of the medium it provided.
return void
        public void SetData(ref FORMATETC formatIn, ref STGMEDIUM medium, bool release)
        {
            // If the format exists in our storage, remove it prior to resetting it
            foreach (KeyValuePair<FORMATETC, STGMEDIUM> pair in storage)
            {
                if ((pair.Key.tymed & formatIn.tymed) > 0
                        && pair.Key.dwAspect == formatIn.dwAspect
                        && pair.Key.cfFormat == formatIn.cfFormat)
                {
                    storage.Remove(pair);
                    break;
                }
            }

            // If release is true, we'll take ownership of the medium.
            // If not, we'll make a copy of it.
            STGMEDIUM sm = medium;
            if (!release)
                sm = CopyMedium(ref medium);

            // Add it to the internal storage
            KeyValuePair<FORMATETC, STGMEDIUM> addPair = new KeyValuePair<FORMATETC, STGMEDIUM>(formatIn, sm);
            storage.Add(addPair);
        }