Share via


IADsCollection::get__NewEnum 方法 (iads.h)

IADsCollection::get__NewEnum 方法會取得相依列舉值對象,這個物件會實作這個 ADSI 集合物件的 IEnumVARIANT。 請注意,函式名稱中有兩個底線字元, (get__NewEnum) 。

語法

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

參數

[out] ppEnumerator

指向這個集合之列舉值物件上 IUnknown 介面指標的指標。

傳回值

這個方法支持標準傳回值,包括 S_OKE_FAILE_NOTIMPL。 如需詳細資訊和其他傳回值,請參閱 ADSI 錯誤碼

備註

當伺服器支援分頁搜尋,且用戶端已指定頁面限制大於伺服器允許的最大搜尋結果時, IADsCollection::get__NewEnum 方法會以下列方式傳回錯誤:

  • 如果伺服器傳回沒有結果的錯誤,函式只會傳回錯誤。
  • 例如,如果伺服器傳回含有或沒有錯誤的部分結果,則伺服器允許的最大搜尋結果,函式會將伺服器的部分結果傳回給使用者。
  • 例如,如果伺服器傳回具有或沒有錯誤的所有結果,例如,每個頁面上的搜尋結果上限,以及透過多個頁面的所有結果,函式會將伺服器的所有結果傳回給使用者。

範例

每個...In...下列 Visual Basic 程式代碼範例中的 Next 語句會隱含地叫用 get__NewEnum 方法。

Dim fso As IADsFileServiceOperations 
On Error GoTo Cleanup

Set fso = GetObject("WinNT://myComputer/Fabrikam01") 
 
Dim coll As IADsCollection
Set coll = fso.Sessions
 
' The following statement invokes IADsCollection::get__NewEnum.
For Each session In coll 
   MsgBox "Session name: " & session.Name
Next session

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

下列 C++ 程式代碼範例示範 如何使用 IADsCollection::get__NewEnum 列舉作用中的檔案服務會話。

HRESULT EnumCollection(IADsCollection *);

HRESULT GetACollectionOfSessions()
{
    LPWSTR adspath = L"WinNT://myComputer/LanmanServer";
    HRESULT hr = S_OK;
    IADsCollection *pColl = NULL;

    // Bind to file service operations.
    IADsFileServiceOperations *pFso = NULL;
    hr = ADsGetObject(adspath,
                      IID_IADsFileServiceOperations,
                      (void**)&pFso);
    if(FAILED(hr)) {goto Cleanup;}

    // Get the pointer to the collection.
    hr = pFso->Sessions(&pColl);
    if(FAILED(hr)) {goto Cleanup;}

    hr = EnumCollection(pColl);

Cleanup:
    if(pColl) pColl->Release();
    if(pFso) pFso->Release();

    return hr;
}

HRESULT EnumCollection(IADsCollection *pColl)
{
    IUnknown *pUnk=NULL;
    HRESULT hr = S_OK;
    // Get the Enumerator object on the collection object.
    hr = pColl->get__NewEnum(&pUnk);
    if(FAILED(hr)) {goto Cleanup;}

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

    // Enumerate the collection.
    BSTR bstr = NULL;
    VARIANT var;
    IADs *pADs = NULL;
    ULONG lFetch;
    IDispatch *pDisp = NULL;

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

Cleanup:
    if(pDisp) pDisp->Release();
    if(pUnk) pUnk->Release();
    if(pColl) pColl->Release();
    if(pEnum) pEnum->Release();
    return hr;
}

規格需求

需求
最低支援的用戶端 Windows Vista
最低支援的伺服器 Windows Server 2008
目標平台 Windows
標頭 iads.h
Dll Activeds.dll

另請參閱

ADSI 錯誤碼

IADsCollection

IEnumVARIANT

IUnknown