本文介绍了Windows 变体强制规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows VARIANT 持有一个带有(据说)数值的 BSTR.

I have a Windows VARIANT holding a BSTR with a (supposedly) numeric value.

我想使用 VariantChangeType 将此 BSTR 值转换为 VT_I4 或 VT_I8 或 ...

I want to use VariantChangeType to convert this BSTR value to a VT_I4 or VT_I8 or ...

令我惊讶的是,传入一个字符串值 "5.6", . 作为我的小数分隔符,该函数成功进行整数转换,结果 lValllVal值为6!我会期望转换错误,或者 5 的值,这就是 sscanf 给我的.

To my surprise, passing in a string value of "5.6", . being my decimal separator, the function succeeds for integer conversion, and the resulting lValor llVal value is 6! I would have expected either a conversion error, or a value of 5, which is what sscanf gives me.

--> VARIANT 转换函数?

我发现 VariantChangeType 是通过(例如)VarI4FromStr,但有信息wrt.此函数使用的转换规则.

I found that VariantChangeType is implemented through (e.g.) VarI4FromStr, but there is zero info wrt. the conversion rules used by this function.

推荐答案

似乎没有与此相关的任何文档.

There does not seem to be any documentation with regard to this.

来自 链接的 MSDN 线程 和一些调试,我可以得出结论:

From the linked MSDN thread and a bit of debugging, I can conclude:

  • VariantChangeType 确实调用了数据类型转换函数(如上所述)
  • VarI4FromStr 似乎在内部调用 VarR8FromStr - 这解释了我们如何进行舍入
  • VarR*FromStr 似乎调用了 VarParseNumFromStr
  • VarParseNumFromStr 似乎没有进一步委托数字解析本身(我在 VS2010 中的快速测试);它没有记录任何解析规则 AFAIK.
  • 舍入似乎使用四舍五入到偶数或一些变体.
  • VariantChangeType does call the Data Type Conversion Functions (as noted)
  • VarI4FromStr seems to call VarR8FromStr internally - this explains how we have rounding
  • VarR*FromStr seems to call VarParseNumFromStr
  • VarParseNumFromStr does not seem to further delegate the numeric parsing itself (quick test of mine in VS2010); it doesn't document any parsing rules AFAIK.
  • Rounding seems to use Round Half to Even or some variation.

这篇关于Windows 变体强制规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 03:01