Directory Services

IADsContainer::get__NewEnum

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
);

Parameters

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

Return Values

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.

Example Code [Visual Basic]

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

Example Code [C++]

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

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.

See Also

ADsBuildEnumerator, ADsEnumerateNext, AdsFreeEnumerator, IADsContainer, IEnumVARIANT, IUnknown