EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

PropVariantToInt32 function

Extracts the Int32 property value of a PROPVARIANT structure. If no value can be extracted, then a default value is assigned.

Syntax


HRESULT PropVariantToInt32(
  _In_   REFPROPVARIANT propvarIn,
  _Out_  LONG *plRet
);

Parameters

propvarIn [in]

Type: REFPROPVARIANT

Reference to a source PROPVARIANT structure.

plRet [out]

Type: LONG*

When this function returns, contains the extracted value if one exists; otherwise, 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 an Int32 value. For instance, an application obtaining values from a property store can use this to safely extract the Int32 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 a conversion is not possible, PropVariantToInt32 will return a failure code and set plRet to 0. See PropVariantChangeType for a list of possible conversions. Of note, VT_EMPTY is successfully converted to 0.

Examples


// 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.

     // PropVariantToInt32 will convert VT_EMPTY to 0.

     INT32 iStatus;

     hr = PropVariantToInt32(propvar, &iStatus);

     if (SUCCEEDED(hr))

     {

             // iStatus is now valid

     }

     else

     {

             // iStatus is always 0

     }

     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
PropVariantToInt32Vector
VariantToInt32
PropVariantChangeType

 

 

Ajouts de la communauté

AJOUTER
Afficher:
© 2014 Microsoft