Partilhar via


PROPVARIANT Helpers #6 - PropVariantCompare[Ex]

In general, PropVariantCompare performs a locale-sensitive comparison between two values and returns <0, 0, or >0 as appropriate.

PropVariantCompare always tries to convert the values to the type of the first value. Thus if code tries to compare values of different types, they will becompared in the context of the first value's type. Different types can lead to weird cases where A<B, but B<A.

For RC1, PropVariantCompare performs a locale sensitive comparison between two values using StrCmpLogicalW. Unfortunately, we didn't think to add a LCID parameter, so you always get the current locale. Maybe we'll create an Ex2 version next time? If you need to compare with a different locale, you may want to perform the comparison yourself, or use VarCmp.

For Vista final, we still haven't added a LCID parameter (boo), but we did add some flags offering different types of string comparisons (StrCmp, StrCmpI, etc). 

// From the RC1 Windows SDK
PSSTDAPI_(int) PropVariantCompareEx(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2, PROPVAR_COMPARE_UNIT unit, PROPVAR_COMPARE_FLAGS flags);
int PropVariantCompare(REFPROPVARIANT propvar1, REFPROPVARIANT propvar2);

typedef enum
{
PVCU_DEFAULT = 0,
PVCU_SECOND = 1,
PVCU_MINUTE = 2,
PVCU_HOUR = 3,
PVCU_DAY = 4,
PVCU_MONTH = 5,
PVCU_YEAR = 6
} PROPVAR_COMPARE_UNIT;

enum tagPROPVAR_COMPARE_FLAGS
{
PVCF_DEFAULT = 0x00000000,
PVCF_TREATEMPTYASGREATERTHAN = 0x00000001, // Empty/null values are greater-than non-empty values
};
typedef int PROPVAR_COMPARE_FLAGS;

Comments

  • Anonymous
    September 26, 2006
    Shell developer Ben Karas has been posting about the property system in the Shell in his new blog The...
  • Anonymous
    September 26, 2006
    As I went through the property helper posts, I kept using those dense word combinations &quot;locale sensitive&quot;...