PropVariantToGUID function (propvarutil.h)

Extracts a GUID value from a PROPVARIANT structure.

Syntax

PSSTDAPI PropVariantToGUID(
  [in]  REFPROPVARIANT propvar,
  [out] GUID           *pguid
);

Parameters

[in] propvar

Type: REFPROPVARIANT

Reference to a source PROPVARIANT structure.

[out] pguid

Type: GUID*

When this function returns, contains the extracted property value if one exists.

Return value

Type: HRESULT

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

Remarks

This helper function works forPROPVARIANT structures of the following types:

  • VT_GUID
  • VT_BSTR
  • VT_LPWSTR
  • VT_ARRAY | VT_UI1

PropVariantToGUID is used in places where the calling application expects a PROPVARIANT to hold a single GUID or GUID value. For instance, an application obtaining values from a property store can use this to safely extract the GUID value for GUID properties.

Examples

// IPropertyStore *ppropstore;

// Assume variable ppropstore is initialized and valid

PROPVARIANT propvar = {0};

HRESULT hr = ppropstore->GetValue(PKEY_Sync_HandlerCollectionID, &propvar);

if (SUCCEEDED(hr))

{

        // PKEY_Sync_HandlerCollectionID is expected to produce a VT_CLSID or VT_EMPTY value.

        // PropVariantToGUID will convert VT_EMPTY to a failure code.

        GUID guidCollectionID;

        hr = PropVariantToGUID(propvar, &guidCollectionID);

        if (SUCCEEDED(hr))

        {

             // guidCollectionID is now valid

        }

        else

        {

            // the extraction failed

        }

        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

See also

InitPropVariantFromCLSID

PropVariantToCLSID

VariantToGUID