如何最好转换VARIANT_BOOL到C ++的布尔? [英] How to best convert VARIANT_BOOL to C++ bool?

查看:946
本文介绍了如何最好转换VARIANT_BOOL到C ++的布尔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用COM布尔值作为在wtypes.h声明的的VARIANT_BOOL传递。也有predefined值的真正的和的的:

When using COM boolean values are to be passed as VARIANT_BOOL which is declared in wtypes.h as short. There are also predefined values for true and false:

#define VARIANT_TRUE ((VARIANT_BOOL)-1)
#define VARIANT_FALSE ((VARIANT_BOOL)0)

这是从VARIANT_BOOL转换成C ++的最好办法布尔键入?显而易见的变体是:

Which is the best way to convert from VARIANT_BOOL to C++ bool type? Obvious variants are:


  1. 与VARIANT_FALSE比较

  1. compare with VARIANT_FALSE

只是投为bool

其他方法可以很容易地创造。

Other ways can be easily invented.

这是做到这一点的最好方法? - 最可读的,最非标准兼容的,最不容易accidential错误种植和最不容易的问题与移植到64位平台。

Which is the best way to do this - most readable, most standart-compliant, least prone to accidential bugs planting and least prone to issues with porting to 64-bit platforms?

推荐答案

相较于 VARIANT_FALSE 。有很多车code的在那里,错误地通过在C ++布尔真正值(转换为整数值1)函数期待 VARIANT_BOOL 。如果你比较 VARIANT_FALSE ,你仍然会得到正确的期望值。

Compare to VARIANT_FALSE. There is a lot of buggy code out there that mistakenly passes in the C++ bool true value (cast to the integer value 1) to a function expecting VARIANT_BOOL. If you compare to VARIANT_FALSE, you will still get the correct expected value.

这篇关于如何最好转换VARIANT_BOOL到C ++的布尔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆