IWMSDiagnosticEvents::get_Item

banner art

Previous Next

IWMSDiagnosticEvents::get_Item

The get_Item method retrieves an IWMSDiagnosticEvent interface from the IWMSDiagnosticEvents collection.

Syntax

  HRESULT get_Item(
  VARIANT  varIndex,   IWMSDiagnosticEvent**  ppVal
);

Parameters

varIndex

[in] VARIANT containing the index of the IWMSDiagnosticEvent interface.

ppVal

[out] Pointer to an IWMSDiagnosticEvent interface. This method calls AddRef internally. To avoid memory leaks, you must call Release when you are finished using the interface.

Return Values

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Return code Number Description
DISP_E_BADINDEX 0x8002000B varIndex is an invalid index location.
E_POINTER 0x80004003 ppVal is a NULL pointer argument.

Example Code

#include <windows.h>
#include <atlbase.h>    // Includes CComVariant.
#include "wmsserver.h"

// Declare variables and interfaces.
IWMSServer              *pServer;
IWMSDiagnosticEvents    *pDiagnosticEvents;
IWMSDiagnosticEvent     *pDiagnosticEvent;

HRESULT         hr;
CComVariant     varIndex;
long            lCount;

// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
                      NULL,
                      CLSCTX_ALL,
                      IID_IWMSServer,
                      (void **)&pServer);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to the IWMSDiagnosticEvents
// interface and retrieve the total count of events.
hr = pServer->get_DiagnosticEvents(&pDiagnosticEvents);
if (FAILED(hr)) goto EXIT;
hr = pDiagnosticEvents->get_Count(&lCount);
if (FAILED(hr)) goto EXIT;

// Retrieve information about each diagnostic event.
for (long x = 0; x < lCount; x++)
{
    varIndex = x;
    hr = pDiagnosticEvents->get_Item(varIndex, &pDiagnosticEvent);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the number of times this event occurred.
    hr = pDiagnosticEvent->get_NumberOfOccurrences(&lCount);
    if (FAILED(hr)) goto EXIT;

    // Release temporary COM objects.
    pDiagnosticEvent->Release();
}

EXIT:
    // TODO: Release temporary COM objects and uninitialize COM.

Requirements

Header: wmsserver.h.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003 family, Windows Server 2008 family.

See Also

Previous Next