Platform SDK: Active Directory, ADSI, and Directory Services

IADsContainer Property Methods

The property methods of the IADsContainer interface get or set the properties described in the following table. For a general discussion of property methods, see Interface Property Methods.

Properties in Vtable Order

Property Description
Count

[Visual Basic]
Access: Read
Data Type: LONG

[C++]
HRESULT get_Count
(
[out] LONG *plCount);

The number of items in the container. When Filter (see the next entry) is set, count returns only the number of filtered items.
Filter

[Visual Basic]
Access: Read/Write
Data Type: VARIANT

[C++]
HRESULT get_Filter
(
[out] VARIANT *pvFilter);


HRESULT put_Filter
(
[in] VARIANT vFilter);

The filter used to select object classes in a given enumeration. This is a variant array, each element of which is the name of a schema class. If Filter is not set or set to empty, all objects of all classes are retrieved by the enumerator.
Hints

[Visual Basic]
Access: Read/Write
Data Type: VARIANT

[C++]
HRESULT get_Hints
(
[out] VARIANT *pvHints);


HRESULT put_Hints
(
[in] VARIANT vHints);

A variant array of BSTR strings. Each element identifies the name of a property found in the schema definition. The vHints parameter allows the client to indicate which attributes to load for each enumerated object. Such information may be used to optimize network access. The exact implementation, however, is provider-specific.

Remarks

The enumeration processes beneath IADsContainer::get__NewEnum and IADsContainer::get_Count are carried out against the contained objects in the cache. When a container contains a large number of objects, the performance may be an issue. To enhance the performance, you should turn off the cache, set up an appropriate page size, and use the IDirectorySearch interface. For this reasons, the get_Count property is not supported in the LDAP provider supplied by Microsoft®.

Example Code [Visual Basic]

The following Visual Basic code snippet shows how the property methods of IADsContainer can be used.

Dim cont as IADsContainer
Dim usr as IADsUser
 
Set cont = GetObject("LDAP://OU=Sales, DC=Fabrikam, DC=COM")
cont.Hints = Array("adminDescription") ' Load only this attribute (optional)
Debug.Print cont.Get("adminDescription")
'We want only users.
cont.Filter = Array("user")
For Each usr In cont
  Debug.Print usr.Name
Next

Example Code [C++]

The following C++ code snippet shows how the property methods of IADsContainer can be used. For brevity, error checking is omitted.

IADsContainer *pCont;
IADs *pChild;
IADs *pADs;
 
HRESULT hr = ADsGetObject(L"LDAP://OU=Sales,DC=Fabrikam,DC=COM",
                          IID_IADsContainer, 
                          (void**)&pCont);
LPWSTR pszArray[] = { L"adminDescription" };
DWORD dwNumber = sizeof(pszArray)/sizeof(LPWSTR);
hr = ADsBuildVarArrayStr( pszArray, dwNumber, &var);
hr = pCont->put_Hints( var );
VariantClear(&var);
 
hr = pCont->QueryInterface(IID_IADs, (void**)pADs);
 
hr = pADs->Get(L"adminDescription", var);
 
LPWSTR pszUsers = {L"user"};
dwNumber = sizeof(pszUsers)/sizeof(LPWSTR);
hr = ADsBuildVarArrayStr(pszUsers, dwNumber, &var);
hr = pCont->put_Filter( var );
VariantClear(&var);
 
// Enumerate user objects in the container
IEnumVARIANT *pEnum = NULL;
hr = ADsBuildEnumerator(pCont, &pEnum);
pCont->Release();    // no longer needed once we have users.
 
ULONG lFetch;
VariantClear(&var);
while (SUCCEEDED(ADsEnumerateNext(pEnum, 1, &var, &lFetch)) && 
                      lFetch==1) {
    hr = V_DISPATCH(&var)->QueryInterface(IID_IADs, (void**)&pChild)
    if(SUCCEEDED(hr)) {
        BSTR bstrName;
        pChild->get_Name(&bstrName);
        printf("  %S\n", bstrName);
        SysFreeString(bstrName);
        pChild->Release();
    }
    VariantClear(&var);
}

See Also

IADsContainer, IDirectorySearch