Interface IEnumWbemClassObject

Rev. 1.01, 27-Aug-98, RayMcc

The IEnumWbemClassObject interface is similar to a standard Component Object Model (COM) enumerator. It works with objects of type IWbemClassObject. However, some extensions over standard COM enumerators have been added to accommodate WBEM requirements.

The enumerator is a logical container of Common Information Model (CIM) objects. It is designed for sequential retrieval. An enumerator has a current position, or cursor, beginning at offset zero, which is the first element, and moves sequentially through the set of objects. When you call the Reset method, once again the current position is set to zero, or the first object. Calling the Next method retrieves the requested objects. It updates the current position so that subsequent calls to Next retrieve the objects. Eventually, you reach the end of the sequence, and cannot retrieve any more objects. At this point, you can restart the enumerator by calling Reset, or you can discard it by using the Release method.

For documentation on the semantics of COM enumerators, see IEnumVariant in the Microsoft® Platform SDK. The IEnumWbemClassObject interface semantically resembles the standard enumerators, except that it is designed also to support asynchronous and semisynchronous call behavior.

This interface is derived from IUnknown and supports its methods.

Methods Description
Reset Resets the cursor position to zero so that the enumeration can be repeated.
Next Retrieves the next object or objects in the enumeration starting from the current position.
NextAsync Retrieves the next object or objects using asynchronous integration with IWbemObjectSink.
Clone Makes a logical copy of the enumerator.
Skip Skips over the object or objects, resulting in a new cursor position.

 


IEnumWbemClassObject::Reset

The IEnumWbemClassObject::Reset method resets the current position of the enumerator to the beginning of the enumeration. Since CIM objects can be dynamic, calling this method does not necessarily return the same list of objects that you obtained previously.

This method will fail if the enumerator was originally created with the WBEM_FLAG_FORWARD_ONLY option.

HRESULT Reset();

Parameters

None.

Return Values

WBEM_S_NO_ERROR The operation succeeded.
WBEM_E_INVALID_OPERATION The operation failed.

DCOM-specific error codes may also be returned if the remote connection to the CIM Object Manager (CIMOM) is lost due to network problems.

If an error code is returned, you can call the COM function GetErrorInfo for more information about the error.


IEnumWbemClassObject::Next

The IEnumWbemClassObject::Next method returns the next object or objects starting at the current cursor position. It then advances the cursor position by uCount objects, so that subsequent calls return the subsequent objects.

HRESULT Next(
    [in]  LONG lTimeOut,
    [in]  ULONG uCount,
    [out] IWbemClassObject **ppObjects,
    [out] ULONG *puReturned
    );

Parameters

lTimeout
Specifies the maximum amount of time in milliseconds that the call will block before returning. If you use the Constant WBEM_INFINITE (-1), the call blocks until objects are available. If you use the value zero (WBEM_NO_WAIT), the call will return immediately, whether any objects are available or not. Negative values other than -1 are invalid.

uCount
The number of requested objects.

ppObjects
A pointer to enough storage to hold the number of IWbemClassObject interface pointers specified by uCount. This storage must be supplied by the caller. This parameter may not be NULL.. The caller must call Release on each of the interface pointers that are received when they are no longer needed.

puReturned
A pointer to a ULONG that receives the number of objects returned. This number can be less than the number requested in uCount. This pointer cannot be NULL.

Notes

The IEnumWbemClassObject::Next method may return WBEM_S_FALSE even when objects have been returned successfully. WBEM_S_NO_ERROR returns only when the number of objects returned matches the number requested in uCount. Therefore, you should use loop termination logic that examines the puReturned value to ensure you have reached the end of the enumeration.

Return Values

WBEM_E_INVALID_PARAMETER One or more invalid parameters were specified in the call.
WBEM_OUT_OF_MEMORY There was not enough memory to complete the enumeration.
WBEM_E_UNEXPECTED An object in the enumeration has been deleted destroying the validity of the enumeration.
WBEM_E_TRANSPORT_FAILURE This indicates the failure of the remote procedure call (RPC) link between the current process and CIMOM.
WBEM_S_NO_ERROR The number of objects returned was the same as the number requested.
WBEM_S_FALSE The number of objects returned was less than the number requested.
WBEM_S_TIMEDOUT A timeout occurred before you obtained all the objects.
WBEM_E_UNKNOWN_OBJECT_TYPE Marshaling received an invalid object type.
WBEM_E_UNKNOWN_PACKET_TYPE Marshaling received an invalid packet type.
WBEM_E_MARSHAL_VERSION_MISMATCH Marshaling version mismatch error.
WBEM_E_MARSHAL_INVALID_SIGNATURE Packet received by marshaling had an invalid (unrecognized) signature.

Note

You may see DCOM-specific error codes returned if network problems cause you to lose the remote connection to CIMOM.
On error, you can call the COM function GetErrorInfo to obtain more error information.

In the following sample, since objects are only requested one at a time, checking the return code to determine loop termination is correct.

void ListObjects(
    IEnumWbemClassObject *pEnum,
    IWbemObjectSink *pSink
    )
{
    HRESULT hRes;
    ULONG uReturned;

   while (1)
    {
IWbemClassObject *pObj = 0;

        hRes = pEnum->Next(0, 1, &pObj, &uReturned);

        if (hRes == WBEM_S_FALSE)
            break;

        ...use object

        pObj->Release();
    }
}

In the next sample, Next may return WBEM_S_FALSE, even though some objects are returned. You need to check uReturned:

void ListObjects2(IEnumWbemClassObject *pEnum)
{

    pEnum->Reset();
    IWbemClassObject *paObjects[10];
    ULONG uReturned;
    HRESULT hRes;

    while (1)
    {
        hRes = pEnum->Next(INFINITE, 10, paObjects, &uReturned);

        if (uReturned == 0)
            break;

        for (ULONG u = 0; u < uReturned; u++)
        {
            IWbemClassObject *pObj = paObjects[u];

 

            // ... use the object

            pObj->Release();

        }
    }

    // Check hRes for other error codes

}

   

 


‹^# $ K + IEnumWbemClassObject::NextAsync¦@¦

<span style=color:#FF0000>[This is preliminary documentation and subject to change.]</span>

Use the IEnumWbemClassObject::NextAsync method when a controlled asynchronous retrieval of objects to a sink is required. Normal asynchronous retrieval, such as a call to IWbemServices::ExecQueryAsync_hmm_IWbemServices_ExecQueryAsync, results in uncontrolled delivery of objects to the caller’s implementation of IWbemObjectSink_hmm_IWbemObjectSink. This method is helpful for cases where components want to control delivery of objects.

HRESULT NextAsync(

[in] ULONG uCount,

[in] IWbemObjectSink *pSink

);

Parameters

uCount

The number of objects being requested.

 

pSink

The sink to receive the objects. The sink must be implemented by the caller. As each batch of objects is requested, they will be delivered to the pSink->Indicate method followed by a final call to pSink->SetStatus. If the sink is going to be used to deliver objects, this API will return WBEM_S_NO_ERROR, even if the number of objects to be delivered is less than requested. However, if there are no more objects remaining, then the pSink parameter will be ingored (no calls to pSink->SetStatus will be made). Instead, this API will return WBEM_S_FALSE.

 

 

Return Values

WBEM_E_FAILED The call failed, and it is not expected to complete.
WBEM_E_INVALID_PARAMETER An invalid parameter was specified.
WBEM_E_UNEXPECTED An object in the enumeration has been deleted destroying the validity of the enumeration.
WBEM_E_OUT_OF_MEMORY There was not enough memory to complete the operation.
WBEM_E_TRANSPORT_FAILURE This indicates the failure of the remote procedure call (RPC) link between the current process and CIMOM.
WBEM_S_NO_ERROR One or more objects successfully returned. It is not considered an error if less objects are returned than requested.
WBEM_S_FALSE This will be returned when no more objects are available.

 

A call to the COM function GetErrorInfo provides more information about the error.

Note

DCOM-specific error codes may also be returned if network problems cause you to lose the remote connection to CIMOM.

 

 

Remarks

This call returns immediately, and delivery to the sink occurs in the background. If multiple calls are made to this method from one or more threads, they are logically queued, and the order of calls and object delivery is preserved. Multiple calls made to this method from one or more threads will block (will not return) until all the sink objects related to previous calls to this method have been serviced. A call to Reset does not affect delivery of objects currently in progress as a result of previous calls. Reset only causes new calls to start at the beginning of the object sequence.

As the objects become available, the caller’s implementation of IWbemObjectSink::Indicate_hmm_IWbemObjectSink_Indicate is called zero or more times to deliver the objects. This is followed by a call to IWbemObjectSink::SetStatus_hmm_IWbemObjectSink_SetStatus with a value of WBEM_S_NO_ERROR if uCount items are returned.

If fewer objects are available than the number requested, IWbemObjectSink::Indicate is called for those objects that are available. This is followed by a call to IWbemObjectSink::SetStatus with a value of WBEM_S_FALSE, or the error code if an error occurred. If there are no available objects, Indicate is not called. However, a final call to IWbemObjectSink::SetStatus will always occur to indicate the status of the entire operation.

Sample Code

void ListObjects(

IEnumWbemClassObject *pEnum,

IWbemObjectSink *pSink

)

{

HRESULT hRes;

while (1)

{

hRes = pEnum->NextAsync(5, pSink);

// Wait until sink is ready for more by

// some private mechanism. Note that hRes gives

// no indication as to whether to continue the

// enumeration or not.

BOOL bContinue = WaitUntilMoreObjectsNeeded();

if (!bContinue)

break;

}

}

‹^# $ K + IEnumWbemClassObject::Clone¦@¦

<span style=color:#FF0000>[This is preliminary documentation and subject to change.]</span>

The IEnumWbemClassObject::Clone method makes a logical copy of the entire enumerator, retaining its current cursor position. This method will make only a "best effort" copy. Due to the dynamic nature of many CIM objects, it is possible that the new enumerator does not enumerate the same set of objects as the source enumerator.

Note

When the enumeration was initialized with the WBEM_FLAG_FORWARD_ONLY flag, IEnumWbemClassObject::Clone is not supported.

 

Note

Any pending asynchronous deliveries begun by NextAsync_hmm_IEnumWbemClassObject_NextAsync are not cloned.

 

HRESULT Clone(

[out] IEnumWbemClassObject **ppEnum

 

);

Parameters

ppEnum

Receives a pointer to a new IEnumWbemClassObject object. The caller must call Release when the interface pointer is no longer required. On error, there will not be a return of a new object.

 

 

Return Values

WBEM_E_FAILED An unspecified error occurred.
WBEM_E_INVALID_PARAMTER The caller passed an invalid parameter.
WBEM_E_OUT_OF_MEMORY There was not enough memory to complete the operation.
WBEM_E_TRANSPORT_FAILURE This indicates the failure of the remote procedure call (RPC) link between the current process and CIMOM.
WBEM_S_NO_ERROR The call succeeds and the cursor position was updated.

 

On error, you can call the COM function GetErrorInfo to obtain more error information.

Note

DCOM-specific error codes may also be returned if network problems cause you to lose the remote connection to CIMOM.

 

Sample Code

BOOL CloneEnum(IEnumWbemClassObject *pSrc)

{

IEnumWbemClassObject *pCopy = 0;

HRESULT hRes = pSrc->Clone(&pCopy);

if (hRes != WBEM_S_NO_ERROR) // Failed to clone it

return FALSE;

// Use the copy of the enumerator

// ...

pCopy->Release();

return TRUE;

}

‹^# $ K + IEnumWbemClassObject::Skip¦@¦

<span style=color:#FF0000>[This is preliminary documentation and subject to change.]</span>

You can use the IEnumWbemClassObject::Skip method to move the current cursor position ahead by a specified number of objects. Also, this affects subsequent calls to NextAsync, but it does not affect pending deliveries begun with NextAsync.

HRESULT Skip(

[in] LONG lTimeOut,

[in] ULONG nCount

);

Parameters

lTimeout

Specifies the maximum amount of time in milliseconds that the call to Skip will block before returning. If you use the constant WBEM_INFINITE (-1), the call will block until the operation succeeds. Negative values other than -1 are invalid. If Skip cannot complete the operation before the lTimeout value expires, the call returns WBEM_S_TIMEDOUT.

 

UCount

Specifies the number of objects to skip. If this parameter is greater than the number of objects left to enumerate then this call will skip to the end of the enumeration and WBEM_S_FALSE will be returned.

 

 

Return Values

WBEM_E_INVALID_PARAMTER The caller passes an invalid parameter.
WBEM_E_OUT_OF_MEMORY There was not enough memory to complete the operation.
WBEM_S_FALSE The call skips less objects than specified by the uCount parameter.
WBEM_S_NO_ERROR The call succeeds and the cursor position was updated.
WBEM_S_TIMEDOUT The lTimeout parameter specified expired before Skip could complete the operation.
WBEM_E_TRANSPORT_FAILURE This indicates the failure of the remote procedure call (RPC) link between the current process and CIMOM.
WBEM_E_FAILED An unspecified error occurred.

 

 

Note

DCOM-specific error codes may also be returned if network problems cause you to lose the remote connection to CIMOM.