VarCmp 返回 0x80020008(错误的变量类型)
我正在尝试使用 VarCmp
函数:
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);
我期望 VarCmp
返回 VARCMP_EQ
但它实际上返回 0x80020008,“错误的变量类型”。这段代码有什么问题?
编辑:我根据乔的评论尝试了一些其他类型,并得到了一些令人惊讶的结果。
不起作用:
- a.vt = VT_UINT; a.uintVal = 32;
CComVariant a((unsigned int)32);
工作:
a.vt = VT_I4; a.lVal = 32;
CComVariant a((long)32);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WINE 页面上的一些有趣且可能相关的评论:“本机 VarCmp 直至并包括 WinXP 不喜欢 I1、UI2、VT_UI4、UI8 和 UINT 作为输入变体。INT 仅作为左变体被接受。”
http://source.winehq.org/WineAPI/VarCmp.html
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