Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

PropVariantToStringVectorAlloc function

Extracts data from a PROPVARIANT structure into a newly allocated strings in a newly allocated vector.

Syntax


HRESULT PropVariantToStringVectorAlloc(
  _In_   REFPROPVARIANT propvar,
  _Out_  PWSTR **pprgsz,
  _Out_  ULONG *pcElem
);

Parameters

propvar [in]

Type: REFPROPVARIANT

Reference to a source PROPVARIANT structure.

pprgsz [out]

Type: PWSTR**

When this function returns, contains a pointer to a vector of strings extracted from source PROPVARIANT structure.

pcElem [out]

Type: ULONG*

When this function returns, containsthe count of string elements extracted from source PROPVARIANT structure.

Return value

Type: HRESULT

This function can return one of these values.

Return codeDescription
S_OK

Returns S_OK if successful, or an error value otherwise.

E_INVALIDARG

The PROPVARIANT was not of the appropriate type.

 

Remarks

This helper function is used in places where the calling application expects a PROPVARIANT to hold a vector of string values.

This helper function works for the followingPROPVARIANTtypes:

  • VT_VECTOR | VT_LPWSTR
  • VT_VECTOR | VT_BSTR
  • VT_ARRAY | VT_BSTR

If the source PROPVARIANT has a supported type, this function extracts a vector of string values into a newly allocated vector of newly allocated strings. The calling application is responsible for using CoTaskMemFree to release both the strings contained in the output vector, and the output vector itself, when they are no longer needed.

If a BSTR in the source PROPVARIANT is NULL, this function will place a newly allocated string containing "" into the output vector.

Examples

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


// IPropertyStore *ppropstore;
// Assume variable ppropstore is initialized and valid
PROPVARIANT propvar = {0};
HRESULT hr = ppropstore->GetValue(PKEY_Keywords, &propvar);
if (SUCCEEDED(hr))
{
         // PKEY_Keywords is expected to produce a VT_VECTOR | VT_LPWSTR, or VT_EMPTY
         // PropVariantToStringVectorAlloc will return an error for VT_EMPTY
         LPWSTR *prgKeywords;
         ULONG cElem;
         hr = PropVariantToStringVectorAlloc (propvar, &prgKeywords, &cElem);
         if (SUCCEEDED(hr))
         {
                 // prgKeywords contains cElem strings
                 for (ULONG i = 0; i < cElem; i++)
                 {
                          CoTaskMemFree(prgKeywords[i]);
                 }
                 CoTaskMemFree(prgKeywords);
         }
         else
         {
                 // propvar either is VT_EMPTY, or contains something other than a vector of  strings
         }
         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

InitPropVariantFromStringVector
PropVariantToString
PropVariantGetStringElem
PropVariantToStringVector
VariantToStringArray

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.