COleVariant中存放字串,这个字串应该存放在COleVariant中的哪个变量中?如何将其转换为CString类型?
另,如果一个MFC函数的参数为LPCTSTR,是否可以直接使用CString为其赋值?

解决方案 »

  1.   

    COleVariant v3 = "字符串";
    CString str =(BSTR)v3.pbstrVal;
      

  2.   

    LPCTSTR的定义如下:
    #ifdef _UNICODE
     typedef const wchar_t * LPCTSTR;
    #else
     typedef const char * LPCTSTR;
    #endifCString做LPCTSTR参数的时候只要加个强制转换就可以
      

  3.   

    USES_CONVERSION;
    CString str = OLE2A(vValue.bstrVal);
      

  4.   

    推荐看看这个
    Visual C++.NET中 字符串转换方法
    http://computer.online.sh.cn/computer/gb/content/2002-12/06/content_477927.htm
    http://computer.online.sh.cn/computer/gb/content/2002-12/06/content_477926.htm