Platform SDK: Active Directory, ADSI, and Directory Services

IADsContainer::get__NewEnum

The IADsContainer::get__NewEnum method creates an enumerator object that implements the IEnumVARIANT interface to enumerate through the children of the container object.

HRESULT IADsContainer::get__NewEnum(
  IUnknown ** ppEnumerator  
);

Parameters

ppEnumerator
[out] Indirect pointer to the IUnknown interface on the enumerator object for this container.

Return Values

This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.

Remarks

There are two underscore characters (__) in the function name between get and NewEnum.

In Visual Basic, you can use the ForEach… statement to invoke the IADsContainer::get__NewEnum method, implicitly.

In C/C++, you can use the ADsBuildEnumerator, ADsEnumerateNext, and AdsFreeEnumerator helper functions.

Example Code [Visual Basic]

The following Visual Basic code snippet shows how to enumerate child objects in a container.

Set cont = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com")
For Each obj In cont
  Debug.Print obj.Name
Next

Example Code [C++]

The following C++ code snippet shows how to enumerate the object contained in a container.

IEnumVARIANT *pEnum;
IADsContainer *pCont;
LPUNKNOWN     pUnk;
VARIANT       var;
IDispatch    *pDisp;
BSTR          bstr;
ulong         lFetch;
IADs         *pADs;
 
// In this sample, skip error checking
ADsGetObject(L"LDAP://OU=Sales,DC=Fabrikam,DC=COM", 
                        IID_IADsContainer, (void**) &pCont);
pCont->get__NewEnum(&pUnk);
pCont->Release();
 
pUnk->QueryInterface(IID_IEnumVARIANT, (void**) &pEnum);
pUnk->Release();
 
// Now Enumerate 
HRESULT hr = pEnum->Next(1, &var, &lFetch);
while(hr == S_OK)
{
    if (lFetch == 1)
    {
        pDisp = V_DISPATCH(&var);
        pDisp->QueryInterface(IID_IADs, (void**)&pADs); 
        pDisp->Release();
        pADs->get_Name(&bstr);
        pADs->Release();
    }
    VariantClear(&var);
    hr = pEnum->Next(1, &var, &lFetch);
};
SysFreeString(bstr);
 
pEnum->Release();

Requirements

  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
  Windows 95/98: Requires Windows 95 or later (with DSClient).
  Header: Declared in Iads.h.

See Also

ADsBuildEnumerator, ADsEnumerateNext, AdsFreeEnumerator, IADsContainer, IEnumVARIANT, IUnknown