PROPVARIANT Helpers #5 – PropVariantChangeType

PropVariantChangeType, aka Mr. Coercion, is the function responsible for all the coercion that goes on in the property system.  It takes a value and attempts to output the same value, but as a different type.  Thus it will convert L"10" to the number 10 and back.

In general, PropVariantChangeType will perform a locale-INsensitive conversion.  This function was intended to operate as part of data layers.  If you need a string you can show the user, use PSFormatForDisplay instead.

PSSTDAPI PropVariantChangeType(__out PROPVARIANT *ppropvarDest, REFPROPVARIANT propvarSrc, PROPVAR_CHANGE_FLAGS flags, VARTYPE vt);

One big difference between PropVariantChangeType and its cousin VariantChangeType is that the PROPVARIANT version will reject many sloppy conversions that VariantChangeType allowed.  For instance, L"xyz" cannot be converted to a number.  Also, an integer cannot be converted to a date. 

Another big different is that PropVariantChangeType avoids locale and attempts to use canonical formats.   For instance, it converts filetimes to L"2006/09/16:20:13:15.001" (the last 001 is the milliseconds).  This makes PropVariantChangeType useful for data layers.

An apology:
We did not invest enough time in this function.  
There are holes in the API.  [Converting a double to a string produces a locale-sensitive format (think L"5,105" in German versus L"5.105" in English].  There is missing functionality.  [Converting ANSI strings to CLSIDs is not supported].  I highly recommend that you test out the scenarios you require of this function.

Comments (2)

  1. TimMisiak says:

    Just found your blog, great stuff! I love reading about the property system.

  2. As I went through the property helper posts, I kept using those dense word combinations "locale sensitive"…

Skip to main content