VariantToDouble function (propvarutil.h)

Extracts a DOUBLE value from a VARIANT structure. If no value can be extracted, then a default value is assigned.

Syntax

PSSTDAPI VariantToDouble(
  [in]  REFVARIANT varIn,
  [out] DOUBLE     *pdblRet
);

Parameters

[in] varIn

Type: REFVARIANT

Reference to a source VARIANT structure.

[out] pdblRet

Type: DOUBLE*

When this function returns, contains the extracted value if one exists; otherwise, 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 when the calling application expects a VARIANT to hold a DOUBLE value. For instance, an application that obtains values from a Shell folder can use this function to safely extract the value from one of the folder's properties whose value is stored as a DOUBLE.

If the source VARIANT is of type VT_R8, this function extracts the DOUBLE value.

If the source VARIANT is not of type VT_R8, the function attempts to convert the value stored in the VARIANT structure into a DOUBLE. If a conversion is not possible, VariantToDouble returns a failure code and sets 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 VariantToDouble to access a DOUBLE value stored in a VARIANT structure.

// VARIANT var;
// Assume variable var is initialize and valid.
// The application expects var to hold a VT_R8 value.
DOUBLE dblValue;

HRESULT hr = VariantToDouble(var, & dblValue);

if (SUCCEEDED(hr))
{
    // dblValue is now valid.
}
else
{
    // dblValue is always FALSE.
}

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

InitVariantFromDouble

PropVariantChangeType

PropVariantToDouble

VariantToDoubleArray