PROPVARIANT Helpers #4 – Vector Helpers


One of the more prominent properties is PKEY_Keywords, e.g. “Tags”.  This is a vector property, and so it usually comes packaged in a PROPVARIANT with VT_VECTOR|VT_LPWSTR.  If you deal with properties such as this, you may find the following helpers useful:



PSSTDAPI_(ULONG) PropVariantGetElementCount(REFPROPVARIANT propvar);
PSSTDAPI PropVariantGetStringElem(REFPROPVARIANT propvar, ULONG iElem, __deref_out PWSTR *ppszVal);


These functions work well together in a loop:



PROPVARIANT propvar = …;
ULONG nElem = PropVariantGetElementCount(propvar);
for (ULONG i = 0; i < nElem; i++)
{
    PWSTR pszVal;
    if (SUCCEEDED(PropVariantGetStringElem(propvar, i, &pszVal)))
    {
        // … do something with pszVal …
        CoTaskMemFree(pszVal);
    }
}


The above code handles VT_EMPTY, VT_LPWSTR, VT_BSTR, VT_VECTOR|VT_LPWSTR, and VT_VECTOR|VT_BSTR typed values.


Of final note is that there are other PropVariantGetXXXElem functions for other supported types.  Check propvarutil.h for the full list.

Comments (1)

  1. The situation I am currently working on version 0.6.0.0 of my Flickr Metadata Synchr tool. The goals