2

如何测试 CComBSTR 是否为空字符串?(没有“文本”值,可以是“”或可以为空)

我的想法:

  1. 测试是否CComBSTR::ByteLength()返回 0
  2. 测试是否CComBSTR::GetStreamSize()返回 0
  3. 测试是否CComBSTR::m_str为 NULL
  4. 测试是否CComBSTR::Length()返回 0

哪一个是正确的方法?如果它们都不是,那么正确的方法是什么?

谢谢。

4

2 回答 2

2

4) 测试长度 0 它的存储速度很快

于 2011-06-17T09:42:33.270 回答
0

3) 测试 CComBSTR::m_str 是否为 NULL

如果您检查 CComBSTR 的源代码,您可以使用几个运算符来执行此测试:

bool CComBSTR::operator!() const throw()
bool CComBSTR::operator!=(int nNull) const throw()
bool CComBSTR::operator==(int nNull) const throw()
operator CComBSTR::BSTR() const throw()

例如:

CComBSTR value;
if (!value) { /* NULL */ } else { /* not NULL */ }
if (value != NULL) { /* not NULL */ } else { /* NULL */ }
if (value == NULL) { /* NULL */ } else { /* not NULL */ }
if ((BSTR) value) { /* not NULL */ } else { /* NULL */ }
于 2014-10-07T11:42:37.447 回答