private DirectoryObject[] ProcessSelections(IDataObject dataObj)
        {
            if (dataObj == null)
                return null;

            DirectoryObject[] selections = null;

            // The STGMEDIUM structure is a generalized global memory handle used for data transfer operations
            STGMEDIUM stg = new STGMEDIUM();
            stg.tymed = (uint)TYMED.TYMED_HGLOBAL;
            stg.hGlobal = IntPtr.Zero;
            stg.pUnkForRelease = null;

            // The FORMATETC structure is a generalized Clipboard format.
            FORMATETC fe = new FORMATETC();
            fe.cfFormat = System.Windows.Forms.DataFormats.GetFormat(CLIPBOARD_FORMAT.CFSTR_DSOP_DS_SELECTION_LIST).Id;
            // The CFSTR_DSOP_DS_SELECTION_LIST clipboard format is provided by the IDataObject obtained
            // by calling IDsObjectPicker::InvokeDialog
            fe.ptd = IntPtr.Zero;
            fe.dwAspect = 1; //DVASPECT_CONTENT    = 1,
            fe.lindex = -1; // all of the data
            fe.tymed = (uint)TYMED.TYMED_HGLOBAL; //The storage medium is a global memory handle (HGLOBAL)

            dataObj.GetData(ref fe, ref stg);

            IntPtr pDsSL = PInvoke.GlobalLock(stg.hGlobal);

            try
            {
                // the start of our structure
                IntPtr current = pDsSL;
                // get the # of items selected
                int cnt = Marshal.ReadInt32(current);

                // if we selected at least 1 object
                if (cnt > 0)
                {
                    selections = new DirectoryObject[cnt];
                    // increment the pointer so we can read the DS_SELECTION structure
                    current = (IntPtr)((int)current + (Marshal.SizeOf(typeof(uint)) * 2));
                    // now loop through the structures
                    for (int i = 0; i < cnt; i++)
                    {
                        // marshal the pointer to the structure
                        DS_SELECTION s = (DS_SELECTION)Marshal.PtrToStructure(current, typeof(DS_SELECTION));
                        //Marshal.DestroyStructure(current, typeof(DS_SELECTION));

                        // increment the position of our pointer by the size of the structure
                        current = (IntPtr)((int)current + Marshal.SizeOf(typeof(DS_SELECTION)));

                        string name = s.pwzName;
                        string path = s.pwzADsPath;
                        string schemaClassName = s.pwzClass;
                        string upn = s.pwzUPN;
                        //string temp = Marshal.PtrToStringUni( s.pvarFetchedAttributes );
                        selections[i] = new DirectoryObject(name, path, schemaClassName, upn);
                    }
                }
            }
            finally
            {
                PInvoke.GlobalUnlock(pDsSL);
                Marshal.FreeHGlobal(stg.hGlobal);
            }
            return selections;
        }
        private DirectoryObject[] ProcessSelections(IDataObject dataObj)
        {
            if (dataObj == null)
            {
                return(null);
            }

            DirectoryObject[] selections = null;

            // The STGMEDIUM structure is a generalized global memory handle used for data transfer operations
            STGMEDIUM stg = new STGMEDIUM();

            stg.tymed          = (uint)TYMED.TYMED_HGLOBAL;
            stg.hGlobal        = IntPtr.Zero;
            stg.pUnkForRelease = null;

            // The FORMATETC structure is a generalized Clipboard format.
            FORMATETC fe = new FORMATETC();

            fe.cfFormat = System.Windows.Forms.DataFormats.GetFormat(CLIPBOARD_FORMAT.CFSTR_DSOP_DS_SELECTION_LIST).Id;
            // The CFSTR_DSOP_DS_SELECTION_LIST clipboard format is provided by the IDataObject obtained
            // by calling IDsObjectPicker::InvokeDialog
            fe.ptd      = IntPtr.Zero;
            fe.dwAspect = 1;                         //DVASPECT_CONTENT    = 1,
            fe.lindex   = -1;                        // all of the data
            fe.tymed    = (uint)TYMED.TYMED_HGLOBAL; //The storage medium is a global memory handle (HGLOBAL)

            dataObj.GetData(ref fe, ref stg);

            IntPtr pDsSL = PInvoke.GlobalLock(stg.hGlobal);

            try
            {
                // the start of our structure
                IntPtr current = pDsSL;
                // get the # of items selected
                int cnt = Marshal.ReadInt32(current);

                // if we selected at least 1 object
                if (cnt > 0)
                {
                    selections = new DirectoryObject[cnt];
                    // increment the pointer so we can read the DS_SELECTION structure
                    current = (IntPtr)((int)current + (Marshal.SizeOf(typeof(uint)) * 2));
                    // now loop through the structures
                    for (int i = 0; i < cnt; i++)
                    {
                        // marshal the pointer to the structure
                        DS_SELECTION s = (DS_SELECTION)Marshal.PtrToStructure(current, typeof(DS_SELECTION));
                        Marshal.DestroyStructure(current, typeof(DS_SELECTION));

                        // increment the position of our pointer by the size of the structure
                        current = (IntPtr)((int)current + Marshal.SizeOf(typeof(DS_SELECTION)));

                        string name            = s.pwzName;
                        string path            = s.pwzADsPath;
                        string schemaClassName = s.pwzClass;
                        string upn             = s.pwzUPN;

                        //string temp = Marshal.PtrToStringUni( s.pvarFetchedAttributes );
                        selections[i] = new DirectoryObject(name, path, schemaClassName, upn);
                    }
                }
            }
            finally
            {
                PInvoke.GlobalUnlock(pDsSL);
            }
            return(selections);
        }