Directory Services

IADsMembers::get__NewEnum

The IADsMembers::get__NewEnum method gets a dependent enumerator object that implements IEnumVARIANT for this ADSI collection object. Be aware that there are two underscore characters in the function name (get__NewEnum).

HRESULT get__NewEnum( 
  IUnknown** ppEnumerator
);

Parameters

ppEnumerator
[out] Pointer to a pointer to the IUnknown interface on the enumerator object for this collection.

Return Values

This method supports the standard return values, including S_OK. For more information about other return values, see ADSI Error Codes.

Example Code [Visual Basic]

The following code example enumerates members of collection.

Dim grp As IADsGroup
On Error GoTo Cleanup

Set grp = GetObject("WinNT://Fabrikam/SaleGroup")
For Each member In Grp
	MsgBox member.Name
Next member

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

Example Code [C++]

The following code example enumerates members of any collection object that supports the IADsMembers interface.

HRESULT EnumMembers(IADsMembers *pMembers)
{
	IUnknown *pUnk;
	HRESULT hr;
	hr = pMembers->get__NewEnum(&pUnk);
	if(FAILED(hr)){goto Cleanup;}

	IEnumVARIANT *pEnum;
	hr = pUnk->QueryInterface(IID_IEnumVARIANT,(void**)&pEnum);
	if(FAILED(hr)){goto Cleanup;}


	// Now Enumerate
	BSTR bstr;
	VARIANT var;
	IADs *pADs;
	ULONG lFetch;
	IDispatch *pDisp;

	VariantInit(&var);
	hr = pEnum->Next(1, &var, &lFetch);
	if(FAILED(hr)){goto Cleanup;}
	while(hr == S_OK)
	{
		if (lFetch == 1)
		{
			 pDisp = V_DISPATCH(&var);
			 pDisp->QueryInterface(IID_IADs, (void**)&pADs);
			 pADs->get_Name(&bstr);
			 printf("MEMBERS: %S\n",bstr);
			 SysFreeString(bstr);
	}
		VariantClear(&var);
		pDisp=NULL;
		hr = pEnum->Next(1, &var, &lFetch);
		if(FAILED(hr)){goto Cleanup;}
};

Cleanup:
	if(pADs) pADs->Release();
	if(pDisp) pDisp->Release();
	if(pUnk) pUnk->Release();
	if(pEnum) pEnum->Release();
	if(bstr) SysFreeString(bstr);
	VariantClear(&var);
	return hr;
}

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

ADSI Error Codes, IADsMembers, IADsMembers Property Methods, IEnumVARIANT, IUnknown