UID | title | description | helpviewer_keywords | old-location | tech.root | ms.assetid | ms.date | ms.keywords | req.header | req.include-header | req.target-type | req.target-min-winverclnt | req.target-min-winversvr | req.kmdf-ver | req.umdf-ver | req.ddi-compliance | req.unicode-ansi | req.idl | req.max-support | req.namespace | req.assembly | req.type-library | req.lib | req.dll | req.irql | targetos | req.typenames | req.redist | ms.custom | f1_keywords | dev_langs | topic_type | api_type | api_location | api_name | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
NF:propvarutil.PropVariantGetStringElem |
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. |
|
properties\PropVariantGetStringElem.htm |
properties |
6e803d93-5b55-4b73-8e23-a584f5f91969 |
12/05/2018 |
PropVariantGetStringElem, PropVariantGetStringElem function [Windows Properties], _shell_PropVariantGetStringElem, properties.PropVariantGetStringElem, propvarutil/PropVariantGetStringElem, shell.PropVariantGetStringElem |
propvarutil.h |
Windows |
Windows XP with SP2, Windows Vista [desktop apps only] |
Windows Server 2003 with SP1 [desktop apps only] |
Propsys.lib |
Propsys.dll (version 6.0 or later) |
Windows |
Windows Desktop Search (WDS) 3.0 |
19H1 |
|
|
|
|
|
|
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.
Type: REFPROPVARIANT
Reference to a source PROPVARIANT structure.
Type: ULONG
The vector or array index; otherwise, iElem must be 0.
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.
Type: HRESULT
If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
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.
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);
}
}
}