IADsCollection::GetObject method (iads.h)

The IADsCollection::GetObject method retrieves an item of the collection.

Syntax

HRESULT GetObject(
  [in] BSTR    bstrName,
  [in] VARIANT *pvItem
);

Parameters

[in] bstrName

The null-terminated Unicode string that specifies the name of the item. This is the same name passed to IADsCollection::Add when the item is added to the collection.

[in] pvItem

Current value of the item. For an object, this corresponds to the IDispatch interface pointer on the object.

Return value

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

Remarks

If you know the name of a session in the Sessions collection, call the IADsCollection::GetObject method explicitly to retrieve the session object.

Examples

The following Visual Basic code example shows how to retrieve a named session object from a collection of active file service sessions.

Dim fso As IADsFileServiceOperations 
Dim ses As IADsSession
Dim coll As IADsCollection
Dim mySessionName As String

Set fso = GetObject("WinNT://myComputer/FabrikamServer") 
Set coll = fso.Sessions

' Insert code to set mySessionName to the name of mySession.
 
' The following statement invokes IADsCollection::GetObject.
Set ses = coll.GetObject(mySessionName)

The following C++ code example shows how to retrieve a named session object from a collection of active file service sessions.

HRESULT GetASessionObjectFromCollection(BSTR mySession)
{
    LPWSTR adspath = L"WinNT://myComputer/FabrikamServer";
    IUnknown *pUnk=NULL;
    HRESULT hr = S_OK;
    IADsCollection *pColl = NULL;
    IADsFileServiceOperations *pFso = NULL;
    IADs *pADsObj = NULL;
    VARIANT varObj;
    BSTR bstrObj = NULL;

    VariantInit(&varObj);
    hr = ADsGetObject(adspath, 
                      IID_IADsFileServiceOperations,
                      (void**)&pFso);
    if(FAILED(hr)) {goto Cleanup;}

    hr = pFso->Sessions(&pColl);
    if(FAILED(hr)) {goto Cleanup;}

    hr = pColl->GetObject(mySession, &varObj);
    V_DISPATCH(&varObj)->QueryInterface(IID_IADs,(void**)&pADsObj);
    hr = pADsObj->get_Class(&bstrObj);
    printf("Class of the object obtained from GetObject: %S\n",
             bstrObj);

Cleanup:
    if(bstrObj) SysFreeString(bstrObj);
    if(pFso) pFso->Release();
    VariantClear(&varObj);
    if(pADsObj) pADsObj->Release();
    if(pColl) pColl->Release();

    return hr;
}

Requirements

Requirement Value
Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
Target Platform Windows
Header iads.h
DLL Activeds.dll

See also

ADSI Error Codes

IADsCollection

IADsCollection::Add

IDispatch

IEnumVARIANT