Export (0) Print
Expand All

IADsMembers::get__NewEnum method

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

Syntax


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

Parameters

ppEnumerator [out]

Pointer to a pointer to the IUnknown interface on the enumerator object for this collection.

Return value

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

Examples

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

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

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

Header

Iads.h

DLL

Activeds.dll

IID

IID_IADsMembers is defined as 451A0030-72EC-11CF-B03B-00AA006E0975

See also

ADSI Error Codes
IADsMembers
IADsMembers Property Methods
IEnumVARIANT
IUnknown

 

 

Show:
© 2015 Microsoft