IADsContainer::get__NewEnum method (iads.h)

The IADsContainer::get__NewEnum method Retrieves an enumerator object for the container. The enumerator object implements the IEnumVARIANT interface to enumerate the children of the container object.

Syntax

HRESULT get__NewEnum(
  [out] IUnknown **retval
);

Parameters

[out] retval

Pointer to an IUnknown pointer that receives the enumerator object. The caller must release this interface when it is no longer required.

Return value

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

Remarks

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

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

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

Examples

The following code example shows how to enumerate child objects in a container.

Dim cont As IADsContainer
On Error GoTo Cleanup

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

Cleanup:
    If(Err.Number<>0) Then
        MsgBox("An error has occurred. " & Err.Number)
    End If
    Set cont = Nothing

The following code example shows how to enumerate the object contained in a container.

IEnumVARIANT *pEnum = NULL;
IADsContainer *pCont = NULL;
LPUNKNOWN pUnk = NULL;
VARIANT var;
IDispatch *pDisp = NULL;
ulong lFetch;
IADs *pADs = NULL;
 
// 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();
 
// Enumerate. 
HRESULT hr = pEnum->Next(1, &var, &lFetch);
while(SUCCEEDED(hr) && lFetch > 0)
{
    if (lFetch == 1)
    {
        BSTR bstr;

        pDisp = V_DISPATCH(&var);
        pDisp->QueryInterface(IID_IADs, (void**)&pADs); 
        pDisp->Release();
        hr = pADs->get_Name(&bstr);
        if(SUCCEEDED(hr))
        {
            SysFreeString(bstr);
        }

        pADs->Release();
    }

    VariantClear(&var);
    hr = pEnum->Next(1, &var, &lFetch);
};

 
pEnum->Release();

Requirements

   
Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
Target Platform Windows
Header iads.h
DLL Activeds.dll

See also

ADsBuildEnumerator

ADsEnumerateNext

AdsFreeEnumerator

IADsContainer

IEnumVARIANT

IUnknown