Selecting a catalog object
Pseudo-code example:
String SelectUsers(HWND hwndParent, IList<String> usersLdapPaths) { IDsObjectPicker objPicker; IDataObject objData; PDSOP_INIT_INFO pInfo; LPWSTR[0..2] attr; HRESULT hr; Result := ''; objPicker = CreateComObject(CLSID_DsObjectPicker) as IDsObjectPicker; System.New(pInfo); try { ZeroMemory(pInfo, SizeOf(DSOP_INIT_INFO)); pInfo.cbSize = SizeOf(DSOP_INIT_INFO); pInfo.pwzTargetComputer = nil;
And an auxiliary function (that I will not try to transcode from one pseudo-code language to another pseudo-code language):
function TActiveDirectory.ReadAttributes(ADataObject: IDataObject; AValues: TStrings): string; var fmtIn: TFormatEtc; stgOut: TStgMedium; pSelList: PDS_SELECTION_LIST; i: Integer; path: string; // x: LongWord; // pVar: POleVariant; items: PDsSelectionArray; begin Result := ''; if Assigned(AValues) then AValues.Clear; if not Assigned(ADataObject) then Exit; stgOut.tymed := TYMED_HGLOBAL; fmtIn.tymed := TYMED_HGLOBAL; fmtIn.cfFormat := RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST); fmtIn.dwAspect := DVASPECT_CONTENT; fmtIn.lindex := -1; if (ADataObject.GetData(fmtIn, stgOut) <> S_OK) then Exit; pSelList := GlobalLock(stgOut.hGlobal); try if pSelList.cItems > 0 then items := PDsSelectionArray(@pSellist.aDsSelection) else items := nil; for i := 0 to pSelList^.cItems-1 do begin // path := TDsSelectionArray(pSellist.aDsSelection)[i].pwzADsPath; path := items[i].pwzADsPath; if Assigned(AValues) then AValues.Add(path); if Result = '' then Result := path; { Result := pSelList^.aDsSelection[i].pwzName+' ('+pSelList.aDsSelection[i].pwzADsPath+')'; AValues.Add(Result); AValues.Add(' Class: '+pSelList^.aDsSelection[i].pwzClass); //"user" AValues.Add(' UPN: '+pSelList^.aDsSelection[i].pwzUPN ); //eg " ian@stackoverflow.com " pVar := pSelList^.aDsSelection[i].pvarFetchedAttributes; for x := 0 to pSelList^.cFetchedAttributes-1 do begin AValues.Add(' '+VarToStr(pVar^)); if x < pSelList^.cFetchedAttributes then Inc(pVar); end;} end; finally GlobalUnlock(stgOut.hGlobal); end; end;
source share