title: Convert COleVariant to CString
body: <p>I have a COleVariant which is set to VT_NULL, when i try and convert the bstrVal member to a CString I get garbage. In older versions of my program however I do not get garbage, I get an empty CString which is my desired behaviour. Here is a simplified version of the offending code: </p>
  
  <pre><code>    COleVariant myCOleVariant;
      myCOleVariant.vt = VT_NULL;
      CString myCString = myCOleVariant.bstrVal;
  </code></pre>
  
  <p>myCOleVariant is set from a database field which can contain a string or could contain NULL. The databse contains mixed types hence using COleVariant. In the specific case which is causing my problems, the database field is NULL and the COleVariant before the conversion to CString is set as VT_NULL.</p>
  
  <p>A simple workaround is to add a function:</p>
  
  <pre><code>    CString COleVariantAsCString(COleVariant pVar)
      {
          CString retval;
  
          if(pVar.vt == VT_NULL || pVar.vt == VT_EMPTY)
              retval = _T("");
          else
              retval = pVar.bstrVal;
  
          return retval;
      }
  </code></pre>
  
  <p>My question is this: Has anything changed in recent versions of visual studio or in windows 7 that would affect the way that COleVariants work? I use COlevariants a lot in my program and am worried that there could be other changes which will cause bugs like this.</p>
  
  <p>I am using VS 2008 professional edition. Any input or ideas would be appreciated as I am quite perplexed by this unexplained change in behaviour. Apologies for the vaugue question. If i knew enough to ask it properly, I probably wouldnt need to ask it.</p>