VarCmp returning 0x80020008 (Bad variable type)

1.4k views Asked by At

I'm trying to compare two VARIANT values in VC++ using the VarCmp function:

VARIANT a;
VariantInit(&a);
a.vt = VT_UINT;
a.uintVal = 32;

VARIANT b;
VariantInit(&b);
b.vt = VT_UINT;
b.uintVal = 32;

HRESULT hr = VarCmp(&a, &b, LOCALE_USER_DEFAULT);

I expected VarCmp to return VARCMP_EQ but it's actually returning 0x80020008, "Bad variable type." What's wrong with this code?

EDIT: I tried some other types based on Joe's comment, and got some surprising results.

Does not work:

  • a.vt = VT_UINT; a.uintVal = 32;
  • CComVariant a((unsigned int)32);

Works:

  • a.vt = VT_I4; a.lVal = 32;
  • CComVariant a((long)32);
1

There are 1 answers

2
Joe On BEST ANSWER

Some interesting and possibly related comments at the WINE page: "Native VarCmp up to and including WinXP doesn't like I1, UI2, VT_UI4, UI8 and UINT as input variants. INT is accepted only as left variant."

http://source.winehq.org/WineAPI/VarCmp.html