EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

PropVariantGetElem function

Initializes a PROPVARIANT structure based on a specified element in another PROPVARIANT structure.

Syntax


HRESULT PropVariantGetElem(
  _In_   REFPROPVARIANT propvarIn,
  _In_   ULONG iElem,
  _Out_  PROPVARIANT *ppropvar
);

Parameters

propvarIn [in]

Type: REFPROPVARIANT

Reference to the source PROPVARIANT structure.

iElem [in]

Type: ULONG

Index of a PROPVARIANT structure element in propvarIn.

ppropvar [out]

Type: PROPVARIANT*

When this function returns, contains a PROPVARIANT with the value specified from the source PROPVARIANT structure.

Return value

Type: HRESULT

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

This helper function works for PROPVARIANT structures of the following types:

  • VT_LPWSTR
  • VT_BSTR
  • VT_BOOL
  • VT_I2
  • VT_I4
  • VT_I8
  • VT_U12
  • VT_U14
  • VT_U18
  • VT_FILETIME
  • VT_VECTOR | (any one of VT_LPWSTR, VT_BSTR, VT_BOOL, VT_I2, VT_I4, VT_I8, VT_U12, VT_U14, VT_U18, VT_FILETIME)
  • VT_ARRAY | (any one of VT_BSTR, VT_BOOL, VT_I2, VT_I4, VT_I8, VT_U12, VT_U14, VT_U18)

Additional types may be supported in the future.

This is an inline function, with its source code provided in the header. It is not included in any .dll or .lib file.

This function extracts a single value from the source PROPVARIANT structure and uses that value to initialize the output PROPVARIANT structure. The calling application must use PropVariantClear to free the PROPVARIANT referred to by ppropvar when it is no longer needed.

If the source PROPVARIANT is a vector or array, iElem must be less than the number of elements in the vector or array.

If the source PROPVARIANT has only a single value, iElem must be 0.

If the source PROPVARIANT is empty, this function always returns an error code.

Note  You can use PropVariantGetElementCount to obtain the number of elements in the vector or array.

Examples

The following code example, to be included as part of a larger program, demonstrates how to use PropVariantGetElem in an iteration statement to access the values in PROPVARIANT.


// PROPVARIANT propvar;
// Assume propvar is initialized and valid.

UINT cElem = PropVariantGetElementCount(propvar);
HRESULT hr = <mark type="const">S_OK</mark>;

for (UINT iElem = 0; SUCCEEDED(hr) && iElem < cElem; iElem ++)
{
   <xref rid="_stg_propvariant"/>propvarElem = {0};
    
    hr = PropVariantGetElem(propvar, iElem, &propvarElem);

    if (SUCCEEDED(hr))
    {
        // propvarElem is valid now.
        PropVariantClear(&propvarElem);
    }
}

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

See also

InitPropVariantFromPropVariantVectorElem

 

 

Contribuições da comunidade

ADICIONAR
Mostrar:
© 2014 Microsoft