PropVariantToDouble function (propvarutil.h)

Extracts double value from a PROPVARIANT structure.

Syntax

PSSTDAPI PropVariantToDouble(
  [in]  REFPROPVARIANT propvarIn,
  [out] DOUBLE         *pdblRet
);

Parameters

[in] propvarIn

Type: REFPROPVARIANT

Reference to a source PROPVARIANT structure.

[out] pdblRet

Type: DOUBLE*

When this function returns, contains the extracted property value if one exists; otherwise, contains 0.0.

Return value

Type: HRESULT

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

This helper function is used in places where the calling application expects a PROPVARIANT to hold a single double floating point value. For instance, an application obtaining values from a property store can use this to safely extract a double value for double properties.

If the source PROPVARIANT has type VT_R8, this helper function extracts the double value. Otherwise, it attempts to convert the value in the PROPVARIANT structure into a double. If a conversion is not possible, PropVariantToDouble will return a failure code and set pdblRet to 0.0. See PropVariantChangeType for a list of possible conversions. Of note, VT_EMPTY is successfully converted to 0.0.

Examples

The following example, to be included as part of a larger program, demonstrates how to use PropVariantToDouble to access a double value in a PROPVARIANT.

// IPropertyStore *ppropstore;
// Assume variable ppropstore is initialized and valid
PROPVARIANT propvar = {0};
HRESULT hr = ppropstore->GetValue(PKEY_Image_HorizontalResolution, &propvar);
if (SUCCEEDED(hr))
{
     // PKEY_Image_HorizontalResolution is expected to produce a VT_R8 or VT_EMPTY value.
     // PropVariantToDouble will successfully convert VT_EMPTY to a 0.0.
     DOUBLE dblHorzResolution;
     hr = PropVariantToDouble(propvar, &dblHorzResolution);
     if (SUCCEEDED(hr))
     {
        // dblHorzResolution is now valid
     }
     else
     {
        // dblHorzResolution contains 0.0
     }
     PropVariantClear(&propvar);
}

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

See also

InitPropVariantFromDouble

PropVariantGetDoubleElem

PropVariantToDoubleWithDefault

VariantToDouble