Platform SDK: Active Directory, ADSI, and Directory Services

Initializing the Object Picker Dialog Box

This topic describes a subroutine that initializes the IDsObjectPicker interface instance. The sample code initializes a DSOP_INIT_INFO structure and passes it to the IDsObjectPicker::Initialize method.

The sample code first initializes a DSOP_SCOPE_INIT_INFO structure to specify that the user can select computer objects from the domain to which the target computer is joined. This example uses a single DSOP_SCOPE_INIT_INFO structure because all specified scope types use the same filters and attributes. To specify additional scope types with different filters and attributes, modify the example to use an array of multiple DSOP_SCOPE_INIT_INFO structures.

The example enables multiple selections by setting the DSOP_FLAG_MULTISELECT flag in the flOptions member of the DSOP_INIT_INFO structure. To allow only a single selection, do not set this flag.

HRESULT InitObjectPicker(
    IDsObjectPicker *pDsObjectPicker) {
 
static const int     SCOPE_INIT_COUNT = 1;
DSOP_SCOPE_INIT_INFO aScopeInit[SCOPE_INIT_COUNT];
DSOP_INIT_INFO  InitInfo;
 
// Initialize the DSOP_SCOPE_INIT_INFO array.
 
ZeroMemory(aScopeInit, 
    sizeof(DSOP_SCOPE_INIT_INFO) * SCOPE_INIT_COUNT);
 
// Combine multiple scope types in a single array entry.
 
aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
aScopeInit[0].flType = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
                     | DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN;
 
// Set uplevel and downlevel filters to include only computer objects.
// Uplevel filters apply to both mixed and native modes.
// Notice that the uplevel and downlevel flags are different.
 
aScopeInit[0].FilterFlags.Uplevel.flBothModes =
        DSOP_FILTER_COMPUTERS;
aScopeInit[0].FilterFlags.flDownlevel = 
        DSOP_DOWNLEVEL_FILTER_COMPUTERS;
 
// Initialize the DSOP_INIT_INFO structure.
 
ZeroMemory(&InitInfo, sizeof(InitInfo));
 
InitInfo.cbSize = sizeof(InitInfo);
InitInfo.pwzTargetComputer = NULL;  // Target is the local computer.
InitInfo.cDsScopeInfos = SCOPE_INIT_COUNT;
InitInfo.aDsScopeInfos = aScopeInit;
InitInfo.flOptions = DSOP_FLAG_MULTISELECT;
 
// You can call Initialize multiple times; last call wins.
// Note that object picker makes its own copy of InitInfo.
 
return pDsObjectPicker->Initialize(&InitInfo);
}