Details of a directory object selected in the DirectoryObjectPickerDialog.
        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;
        }
        public void SecurityViewModel_PickWindowsGroupCommand_ResultIsNotNull_PermissionWindowsGroupIsUpdated()
        {
            //------------Setup for test--------------------------
            var resourceID = Guid.NewGuid();
            const string ResourceName = "Cat\\Resource";
            var permission = new WindowsGroupPermission
            {
                IsServer = false,
                WindowsGroup = "Deploy Admins",
                View = false,
                Execute = false,
                Contribute = false,
                DeployTo = true,
                DeployFrom = true,
                Administrator = false,
                ResourceID = resourceID,
                ResourceName = ResourceName
            };

            var directoryObj = new DirectoryObject("Administrators", "WinNT://dev2/MyPC/Administrators", "Group", "", new object[1]);

            var picker = new Mock<DirectoryObjectPickerDialog>();

            var viewModel = new TestSecurityViewModel(new SecuritySettingsTO(new[] { permission }), new Mock<IResourcePickerDialog>().Object, picker.Object, new Mock<IWin32Window>().Object, new Mock<IEnvironmentModel>().Object) { Result = DialogResult.OK, SelectedObjects = new[] { directoryObj } };
            //------------Execute Test---------------------------
            viewModel.PickWindowsGroupCommand.Execute(viewModel.ResourcePermissions[0]);

            //------------Assert Results-------------------------
            Assert.AreEqual(directoryObj.Name, viewModel.ResourcePermissions[0].WindowsGroup);
        }
        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);
        }