| Platform SDK: Active Directory, ADSI, and Directory Services |
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 );
This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.
There are two underscore characters (__) in the function name between get and NewEnum.
In Visual Basic, you can use the For…Each… statement to invoke the IADsContainer::get__NewEnum method, implicitly.
In C/C++, you can use the ADsBuildEnumerator, ADsEnumerateNext, and AdsFreeEnumerator helper functions.
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
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();
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.
ADsBuildEnumerator, ADsEnumerateNext, AdsFreeEnumerator, IADsContainer, IEnumVARIANT, IUnknown