PropVariantToInt32WithDefault
TOC
Collapse the table of content
Expand the table of content

PropVariantToInt32WithDefault function

Extracts an Int32 value from a PROPVARIANT structure. If no value currently exists, then the specified default value is returned.

Syntax


LONG PropVariantToInt32WithDefault(
  _In_ REFPROPVARIANT propvarIn,
  _In_ LONG           lDefault
);

Parameters

propvarIn [in]

Type: REFPROPVARIANT

Reference to a source PROPVARIANT structure.

lDefault [in]

Type: LONG

Specifies a default property value, for use where no value currently exists.

Return value

Type: LONG

Returns extracted LONG value, or default.

Remarks

This helper function is used in places where the calling application expects a PROPVARIANT to hold a LONG value and would like to use a default value if it does not. For instance, an application obtaining values from a property store can use this to safely extract the LONG value for Int32 properties.

If the source PROPVARIANT has type VT_I4, this helper function extracts the LONG value. Otherwise, it attempts to convert the value in the PROPVARIANT structure into a LONG. If the source PROPVARIANT has type VT_EMPTY or a conversion is not possible, then PropVariantToInt32WithDefault will return the default provided by lDefault. See PropVariantChangeType for a list of possible conversions.

Examples

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


// IPropertyStore *ppropstore;
// Assume variable ppropstore is initialized and valid
PROPVARIANT propvar = {0};
HRESULT hr = ppropstore->GetValue(PKEY_FlagStatus, &propvar);
if (SUCCEEDED(hr))
{
     // PKEY_FlagStatus is expected to produce a VT_I4 or VT_EMPTY value.
     // The application developer decided to treat VT_EMPTY or invalid values as 0
     LONG iStatus = PropVariantToInt32WithDefault(propvar, 0);
     // iStatus is now valid.
     PropVariantClear(&propvar);
}

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

InitPropVariantFromInt32
PropVariantToInt32
VariantToInt32
PropVariantChangeType

 

 

Show:
© 2016 Microsoft