2011-06-17 6 views
2

Comment tester si un CComBSTR est une chaîne vide? (Sans valeur 'texte', peut être "" ou peut être nul)comment tester si CComBSTR est vide

mes idées:

  1. test si CComBSTR::ByteLength() renvoie 0
  2. test si CComBSTR::GetStreamSize() renvoie 0
  3. test si CComBSTR::m_str est- NULL
  4. test si CComBSTR::Length() renvoie 0

dont l'une est correcte approche? si aucun d'eux n'est, alors quelle est la bonne approche?

merci.

Répondre

2

4) Durée de l'épreuve 0, il est rapide comme il est stocké essai

+0

en fait, il en résulte étant 'SysStringLength()' calle d qui n'est pas la chose la plus rapide du monde. – sharptooth

+2

Pourquoi c'est lent? Ils sont ajoutés au début. – Tom

0

3) si CComBSTR :: m_str est NULL

Si vous vérifiez le code source de CComBSTR il y a plusieurs opérateurs que vous pouvez utiliser pour faire ce test :

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

Par exemple:

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 */ } 
Questions connexes