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.PropVariantToUInt16 |
PropVariantToUInt16 function (propvarutil.h) |
Extracts a unsigned short value from a PROPVARIANT structure. If no value can be extracted, then a default value is assigned. |
|
properties\PropVariantToUInt16.htm |
properties |
4499842b-c802-4328-b463-f3cfb270e635 |
12/05/2018 |
PropVariantToUInt16, PropVariantToUInt16 function [Windows Properties], properties.PropVariantToUInt16, propvarutil/PropVariantToUInt16, shell.PropVariantToUInt16, shell_PropVariantToUInt16 |
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 unsigned short value from a PROPVARIANT structure. If no value can be extracted, then a default value is assigned.
Type: REFPROPVARIANT
Reference to a source PROPVARIANT structure.
Type: USHORT*
When this function returns, contains the extracted property value if one exists; otherwise, 0.
Type: HRESULT
If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
This helper function is used in places where the calling application expects a PROPVARIANT to hold a unsigned short value. For instance, an application obtaining values from a property store can use this to safely extract the unsigned short value for UInt16 properties.
If the source PROPVARIANT has type VT_UI2, this helper function extracts the unsigned short value. Otherwise, it attempts to convert the value in the PROPVARIANT structure into a USHORT. If a conversion is not possible, PropVariantToUInt16 will return a failure code and set puiRet to 0. See PropVariantChangeType for a list of possible conversions. Of note, VT_EMPTY is successfully converted to 0.
The following example, to be included as part of a larger program, demonstrates how to use PropVariantToUInt16 to access a unsigned short value in a PROPVARIANT.
// IPropertyStore *ppropstore;
// Assume variable ppropstore is initialized and valid
PROPVARIANT propvar = {0};
HRESULT hr = ppropstore->GetValue(PKEY_FlagColor, &propvar);
if (SUCCEEDED(hr))
{
// PKEY_FlagColor is expected to produce a VT_UI2 or VT_EMPTY value.
// PropVariantToUInt16 will convert VT_EMPTY to 0.
USHORT uColor;
hr = PropVariantToUInt16(propvar, & uColor);
if (SUCCEEDED(hr))
{
// uColor is now valid
}
else
{
// uColor is always 0
}
PropVariantClear(&propvar);
}