BSTR && std::string

 

BSTR  to std::string

 

#include 

// this is the BSTR
BSTR Bstr = ::SysAllocString(L"Hello World"); 

// covert to std::string
_bstr_t bstr_t(Bstr);
std::string str(bstr_t);


// free the BSTR
::SysFreeString(Bstr);


std::string  to  BSTR

 

std::string name = "ni hao me";

    _bstr_t bstr_t(name.c_str());//取name的字符串形式

    BSTR ret_val = bstr_t.GetBSTR(); //得到BSTR 
 

你可能感兴趣的:(MFC)