PropVariantGetStringElem function (propvarutil.h)
Extracts a single Unicode string element from a PROPVARIANT structure of type VT_LPWSTR, VT_BSTR, VT_VECTOR | VT_LPWSTR, VT_VECTOR | VT_BSTR, or VT_ARRAY | VT_BSTR.
Syntax
PSSTDAPI PropVariantGetStringElem(
[in] REFPROPVARIANT propvar,
[in] ULONG iElem,
[out] PWSTR *ppszVal
);
Parameters
[in] propvar
Type: REFPROPVARIANT
Reference to a source PROPVARIANT structure.
[in] iElem
Type: ULONG
The vector or array index; otherwise, iElem must be 0.
[out] ppszVal
Type: PWSTR*
When this function returns, contains the extracted string value. The calling application is responsible for freeing this string by calling CoTaskMemFree when it is no longer needed.
Return value
Type: HRESULT
If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Remarks
This helper function works for PROPVARIANT structures of the following types:
- VT_LPWSTR
- VT_BSTR
- VT_VECTOR | VT_LPWSTR
- VT_VECTOR | VT_BSTR
- VT_ARRAY | VT_BSTR
If a BSTR element has a NULL pointer, this function allocates an empty string.
Examples
The following code example, to be included as part of a larger program, demonstrates how to use PropVariantGetStringElem with an iteration statement to access the values in a PROPVARIANT.
// PROPVARIANT propvar;
// Assume the variable propvar is initialized and valid
if ((propvar.vt & VT_TYPEMASK) == VT_LPWSTR || (propvar.vt & VT_TYPEMASK) == VT_BSTR)
{
UINT cElem = PropVariantGetElementCount(propvar);
HRESULT hr = <mark type="const">S_OK</mark>;
for (UINT iElem = 0; SUCCEEDED(hr) && iElem < cElem; iElem ++)
{
PWSTR pszValue;
hr = PropVariantGetStringElem(propvar, iElem, &pszValue);
if (SUCCEEDED(hr))
{
// pszValue is valid now
CoTaskMemFree(pszValue);
}
}
}
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP with SP2, Windows Vista [desktop apps only] |
Minimum supported server | Windows Server 2003 with SP1 [desktop apps only] |
Target Platform | Windows |
Header | propvarutil.h |
Library | Propsys.lib |
DLL | Propsys.dll (version 6.0 or later) |
Redistributable | Windows Desktop Search (WDS) 3.0 |