IWMSContext::SetArrayValue
Previous | Next |
IWMSContext::SetArrayValue
The SetArrayValue method specifies a pointer to a SAFEARRAY.
Syntax
HRESULT SetArrayValue( LPCWSTR pstrName, long lNameHint, SAFEARRAY(BSTR) psaValue, long lOptions );
Parameters
pstrName
[in] LPCWSTR specifying the name portion of the name-value pair in the context.
lNameHint
[in] long containing an optional key that can be used to more efficiently access a value.
psaValue
[in] Pointer to a SAFEARRAY of BSTR values.
lOptions
[in] long containing either zero or the WMS_CONTEXT_SET_PROPERTY_NAME_BY_VALUE enumeration flag defined in the WMS_CONTEXT_OPTIONS enumeration type. By default, the name is specified by reference.
Return Values
If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.
Return code | Number | Description |
E_INVALIDARG | 0x80070057 | The psaValue parameter or the pstrName parameter is NULL. |
E_OUTOFMEMORY | 0x8007000E | Could not allocate memory for the value. |
Remarks
The current release has no public contexts that contain a SAFEARRAY value, but you can set a custom value in a context and retrieve it later. The server does not recognize custom values.
Example Code
// Declare variables HRESULT hr = S_OK; SAFEARRAY* pSA = NULL; SAFEARRAYBOUND rgsabound[1]; CComBSTR bstrColor[3]; long lSAIndex = 0; int nColorIndex = 0; // Create an array of BSTRs. bstrColor[nColorIndex++] = L"Red"; bstrColor[nColorIndex++] = L"Blue"; bstrColor[nColorIndex++] = L"Green"; // Specify the bounds for the SAFEARRAY. rgsabound[0].lLbound = 0; rgsabound[0].cElements = nColorIndex; // Create the SAFEARRAY. pSA = SafeArrayCreate(VT_VARIANT, 1, rgsabound); if (NULL == pSA) { return E_OUTOFMEMORY; } // Fill the SAFEARRAY with values. for (lSAIndex=0; lSAIndex<nColorIndex && SUCCEEDED(hr); lSAIndex++) { VARIANT varElement; VariantInit(&varElement); V_VT(&varElement) = VT_BSTR; V_BSTR(&varElement) = bstrColor[lSAIndex]; hr = SafeArrayPutElement(pSA, &lSAIndex, &varElement); VariantClear(&varElement); } if (FAILED(hr)) goto EXIT; // Use a pointer to an existing context to add a SAFEARRAY. if (NULL != pUSerContext) { hr = pUSerContext->SetArrayValue( L"SafeArray", WMS_CONTEXT_NO_NAME_HINT, pSA, WMS_CONTEXT_SET_PROPERTY_NAME_BY_VALUE if (FAILED(hr)) goto EXIT; } EXIT: // Release the SAFEARRAY. SafeArrayDestroy(pSA); pSA = NULL; //TODO: Release temporary objects.
Requirements
Header: wmscontext.h.
Library: WMSServerTypeLib.dll.
Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.
See Also
Previous | Next |