PropVariantToBooleanWithDefault function (propvarutil.h)
Extracts the Boolean property value of a PROPVARIANT structure. If no value exists, then the specified default value is returned.
Syntax
PSSTDAPI_(BOOL) PropVariantToBooleanWithDefault(
[in] REFPROPVARIANT propvarIn,
[in] BOOL fDefault
);
Parameters
[in] propvarIn
Type: REFPROPVARIANT
Reference to a source PROPVARIANT structure.
[in] fDefault
Type: BOOL
Specifies the default property value, for use where no value currently exists.
Return value
Type: BOOL
The extracted Boolean value or the default value.
Remarks
This helper function is used in places where the calling application expects a PROPVARIANT to hold a Boolean value and would like to use a default value if it does not. For instance, an application that obtains values from a property store can use this to safely extract the Boolean value for Boolean properties.
If the source PROPVARIANT has type VT_BOOL, this helper function extracts the Boolean value. Otherwise, it attempts to convert the value in the PROPVARIANT structure into a Boolean. If the source PROPVARIANT has type VT_EMPTY or a conversion is not possible, then PropVariantToBooleanWithDefault returns the default provided by fDefault. 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 PropVariantToBooleanWithDefault to access a Boolean value in a PROPVARIANT.
// IPropertyStore *ppropstore;
// Assume the variable ppropstore is initialized and valid.
PROPVARIANT propvar = {0};
HRESULT hr = ppropstore->GetValue(PKEY_IsRead, &propvar);
if (SUCCEEDED(hr))
{
// PKEY_IsRead is expected to produce a VT_BOOL or VT_EMPTY value.
// The application developer decided to treat VT_EMPTY or invalid values as TRUE
BOOL fShared = PropVariantToBooleanWithDefault(propvar, TRUE);
// fShared is now valid.
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 |