_variant_t temp = m_pRecordset->GetCollect(mpnb);
        temp.ChangeType(VT_BSTR);//把temp转化为CString对象
CString str2;
         str2=temp.bstrVal;
        temp.ChangeType(VT_BSTR);这句话的作用是什么啊,尤其是VT_BSTR这个参数是什么意思?
        

解决方案 »

  1.   

    Microsoft SpecificChanges the type of the _variant_t object to the indicated VARTYPE. 
    void ChangeType(
       VARTYPE vartype,
       const _variant_t* pSrc = NULL 
    );
     Parameters
    vartype
    The VARTYPE for this _variant_t object.pSrc
    A pointer to the _variant_t object to be converted. If this value is NULL, conversion is done in place.Res
    This member function converts a _variant_t object into the indicated VARTYPE. If pSrc is NULL, the conversion is done in place, otherwise this _variant_t object is copied from pSrc and then converted.END Microsoft Specific
      

  2.   

    但是我感觉没有 temp.ChangeType(VT_BSTR);好象也没有关系。
    .bstrVal是_variant_t类的变量吧
      

  3.   

    比如之前你放一个int类型到_variant_t里面
    然后你需要一个字符串类型,但_variant_t存的不是,
    调用ChangeType之后_variant_t里面存的就是BSTR类型的数据了