IWMSNamedValues::put_Item

banner art

Previous Next

IWMSNamedValues::put_Item

The put_Item method inserts or modifies a name-value pair in the IWMSNamedValues collection.

Syntax

  HRESULT put_Item(
  const VARIANT  varIndex,
  VARIANT  varValue
);

Parameters

varIndex

[in] VARIANT containing either the name portion of the name-value pair or an index into the collection. The maximum size of a name is 250 characters.

pVal

[in] VARIANT containing the value portion of the name-value pair.

Return Values

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

Return code Number Description
NS_E_NAMESPACE_BAD_NAME 0xC00D1396L varIndex contains an invalid character. Invalid characters are: & " ' < > \ and the ANSI characters 0-31 and 127.
NS_E_NAMESPACE_NAME_TOO_LONG 0xC00D1392L varValue is greater than the maximum length allowed.
NS_E_NAMESPACE_WRONG_TYPE 0xC00D138BL varValue is an unsupported VARIANT type.

Remarks

If you supply a name and no matching name is found in the collection, the put_Item method creates a new IWMSNamedValue interface containing the name and value you specify. If the name-value pair already exists, the value portion is updated.

If you enter an integer index and no matching index is found in the collection, the put_Item method returns an error.

Example Code

#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;

// Add a new property to the collection of name-value pairs.
bstrName = "System Administrator";
varValue = "Bob Jenkins";
hr = pNamedValues->Add(bstrName, varValue, &pNamedValue);
if (FAILED(hr)) goto EXIT;

// Modify the existing name-value pair of the same name.
varIndex = "System Administrator";
varValue = "Justin Crouch";
hr = pNamedValues->put_Item(varIndex, varValue);
if (FAILED(hr)) goto EXIT;

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