VarCmp returning 0x80020008 (Bad variable type)

2

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);
visual-c++
variant
hresult
asked on Stack Overflow Jan 25, 2012 by M. Dudley • edited Jan 25, 2012 by M. Dudley

1 Answer

1

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

answered on Stack Overflow Jan 25, 2012 by Joe

User contributions licensed under CC BY-SA 3.0