IWMSNamedValues::Add

banner art

Previous Next

IWMSNamedValues::Add

The Add method adds an IWMSNamedValue interface to the IWMSNamedValues collection.

Syntax

  HRESULT Add(
  BSTR  szName,
  VARIANT  varValue,
  IWMSNamedValue**  pItem
);

Parameters

szName

[in] BSTR containing the name.

varValue

[in] VARIANT containing the value. The default value is a zero-length string.

pItem

[out] Pointer to a pointer to the new IWMSNamedValue 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
E_OUTOFMEMORY 0x8007000E There is insufficient memory to complete the function.
NS_E_NAMESPACE_BAD_NAME 0xC00D1396L szName 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

You can use any VARIANT data type except VT_UNKNOWN, VT_DISPATCH, VT_ARRAY, VT_R4, or VT_DATE.

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;

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