zoukankan      html  css  js  c++  java
  • CString、TCHAR、WCHAR 字符串等转BSTR的几种方法。

    1._bstr_t 

    _bstr_t bstrText = _T("aaaa");
    CString strText(_T("aaaa"));
    bstrText = strText; 

    其它字符串方法雷同。

    优点:使用方法简单。

    缺点:需要如下引用文件

    Header: comutil.h

    Lib: comsuppw.lib or comsuppwd.lib

     

    2.CComBSTR

    CComBSTR bstrText = _T("aaaa);
    CString strText(_T("aaaa));
    bstrText = strText;

    优点:使用方便

    缺点:不能直接赋值const类型的字符串(如LPCTSTR)

     

    3.CString 直接转换

    CString strText(_T("aaaa"));
    BSTR bstrText = strText.AllocSysString();
    SysFreeString(bstrText);

    优点:不用借助其他类

    缺点:需要自己分配以及释放内存  

      

     

  • 相关阅读:
    python socket 二进制
    全面介绍内存管理机制
    glog修改
    mysql c api
    http twisted
    IOCP 模型1
    IOCP 模型2 AcceptEx
    python
    Python Twisted
    Java 拾遗
  • 原文地址:https://www.cnblogs.com/lebronjames/p/2988410.html
Copyright © 2011-2022 走看看