Directory Services |
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.
HRESULT get__NewEnum( IUnknown** ppEnumerator );
There are two underscore characters (__) in the function name between get and NewEnum.
In Visual Basic, use the For…Each statement to invoke the IADsContainer::get__NewEnum method implicitly.
In C/C++, use the ADsBuildEnumerator, ADsEnumerateNext, and AdsFreeEnumerator helper functions.
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();
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.
ADsBuildEnumerator, ADsEnumerateNext, AdsFreeEnumerator, IADsContainer, IEnumVARIANT, IUnknown