IWMSNamedValues::get_Item

The get_Item method retrieves a name-value pair from the IWMSNamedValues collection.

HRESULT get_Item(
  const VARIANT  varIndex,
  IWMSNamedValue**  pVal
);

Arguments

varIndex

[in] VARIANT containing either the name portion of the name-value pair or an index into the collection.

pVal

[out] Pointer to a pointer to an IWMSNamedValueIWMSNamedValue Interface. You can use this interface to retrieve the name-value pair. This method calls AddRef internally. To avoid memory leaks, you must call Release when you are finished using the interface.

Return Value

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

pVal is a NULL pointer argument.

Example

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

// Declare variables and interfaces.
IWMSServer      *pServer;
IWMSNamedValues *pNamedValues;
IWMSNamedValue  *pNamedValue;

HRESULT         hr;
CComVariant     varIndex;
CComVariant     varValue;
CComBSTR        bstrName;
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 an IWMSNamedValues interface
// containing descriptive information about the server.
hr = pServer->get_Properties(&pNamedValues);
if (FAILED(hr)) goto EXIT;

// Retrieve the total count of name-value pairs.
hr = pNamedValues->get_Count(&lCount);
if (FAILED(hr)) goto EXIT;

// Retrieve information about each name-value pair.
for (long x = 0; x < lCount; x++) {
    varIndex = x;
    hr = pNamedValues->get_Item(varIndex, &pNamedValue);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the name associated with this pair.
    hr = pNamedValue->get_Name(&bstrName);
    if (FAILED(hr)) goto EXIT;

    // Release temporary COM objects.
    pNamedValue->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

Reference

IWMSNamedValue Interface

IWMSNamedValues Interface