VariantToDouble
TOC
Collapse the table of content
Expand the table of content

VariantToDouble function

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

Syntax


HRESULT VariantToDouble(
  _In_  REFVARIANT varIn,
  _Out_ DOUBLE     *pdblRet
);

Parameters

varIn [in]

Type: REFVARIANT

Reference to a source VARIANT structure.

pdblRet [out]

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

Minimum supported client

Windows XP with SP2, Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2003 with SP1 [desktop apps only]

Redistributable

Windows Desktop Search (WDS) 3.0

Header

Propvarutil.h

Library

Propsys.lib

DLL

Propsys.dll (version 6.0 or later)

See also

InitVariantFromDouble
VariantToDoubleArray
PropVariantToDouble
PropVariantChangeType

 

 

Show:
© 2016 Microsoft