IWbemHiPerfProvider::QueryInstances method

The IWbemHiPerfProvider::QueryInstances method returns instances of the specified class using the supplied IWbemObjectSink instance. The method should return immediately. The IWbemObjectSink interface is used to specify results.

Note  If a provider does not implement this method, it must return WBEM_E_PROVIDER_NOT_CAPABLE.


HRESULT QueryInstances(
  [in] IWbemServices   *pNamespace,
  [in] WCHAR           *wszClass,
  [inlong            lFlags,
  [in] IWbemContext    *pCtx,
  [in] IWbemObjectSink *pSink


pNamespace [in]

An IWbemServices pointer back to WMI that can service any request from the provider. The provider should call AddRef on this pointer if it needs to call back to WMI during execution.

wszClass [in]

Pointer to a WCHAR string that specifies the class whose instances are returned.

lFlags [in]

Integer that contains the flags.

pCtx [in]

Typically NULL; otherwise, a pointer to an IWbemContext object that is required by one or more dynamic class providers. The values in the context object must be specified in the provider documentation. For more information, see Making Calls to WMI.

pSink [in]

Pointer to the IWbemObjectSink implementation that is provided by the client to any of the asynchronous methods of IWbemServices.

Return value

This method returns an HRESULT that indicates the status of the method call. The following table lists the value contained within an HRESULT.

Return codeDescription

The current user does not have permission to retrieve the specified instance.


The provider failed internally, even though the operation was valid.


The requested instance could not be found.


The provider cannot enumerate instances regardless of whether it recognizes the name. Return this error code in all cases if a more specific code is not required.


The method was successful.


HiPerf providers can report success or failure either through the return code from QueryInstances or through a call to the SetStatus method of pResponseHandler. If you call the SetStatus method, the return code sent through pResponseHandler takes precedence over the QueryInstances return code.


WMI calls QueryInstances in response to an IWbemServices::CreateInstanceEnum or IWbemServices::CreateInstanceEnumAsync request.

The IWbemObjectSink::SetStatus method is called to indicate the end of the result set. When error conditions occur, IWbemObjectSink::SetStatus may also be called with no intervening calls to IWbemObjectSink::Indicate.


The following code example shows how to implement QueryInstances.

HRESULT CMyHiPerfProvider::QueryInstances(
    /* [in] */ IWbemServices* pNamespace,  
    /* [in] */ BSTR strClass,
    /* [in] */ long lFlags,
    /* [in] */ IWbemContext __RPC_FAR *pCtx,
    /* [in] */ IWbemObjectSink __RPC_FAR *pSink
   IWbemClassObject *pClass = 0;
   IWbemClassObject *pNextInst = 0;

   // The IWbemObjectSink interface must be
   // implemented in a class that you define. You then
   // must assign the pResponseHandler pointer
   // an instance of the class that implements
   // the IWbemObjectSink interface.
   IWbemObjectSink* pResponseHandler = 0;
   HRESULT hRes;

    // Use the namespace pointer to retrieve a class
    // definition.

   hRes = pNamespace ->GetObject(strClass, 0, NULL, &pClass, 0);
   if (WBEM_NO_ERROR==hRes)
       return hRes;

    // Now loop through the private source and create each instance.

     for (int i = 0 ; i < NUM_OF_INSTANCES ; i++)
         hRes = pClass->SpawnInstance(0, &pNextInst);

         // Exit loop if no new instance is spawned
         if (WBEM_S_FALSE == hRes)

        // Create the instance.
        // For example, call a function (FillInst) that
        // assigns a value to the pNextInst pointer.

        // Deliver the class to WMI.
        pResponseHandler->Indicate(1, &pNextInst);

   // Send a finish message to WMI.
    pResponseHandler->SetStatus(0, WBEM_S_NO_ERROR, 0, 0);
    // Free memory resources.

  return WBEM_S_NO_ERROR;


Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003


Wbemprov.h (include Wbemidl.h)





See also

Developing a WMI Provider
Writing an Instance Provider
Making an Instance Provider into a High-Performance Provider
Performance Counter Provider



© 2015 Microsoft