如何连接CComBSTR
和字符串?
我试过这种方式:
CComBSTR a = "DEF";
CComBSTR strRequete = "ABC'" + a + "GHI"; //marked line
但我在a
的{{1}}告诉我
错误:表达式必须具有整数或未整合的枚举类型。
非常感谢!
答案 0 :(得分:3)
要连接,您有8 methods:
HRESULT Append(LPCOLESTR lpsz, int nLen);
HRESULT Append(LPCOLESTR lpsz);
HRESULT Append(LPCSTR);
HRESULT Append(char ch);
HRESULT Append(wchar_t ch);
HRESULT Append(const CComBSTR& bstrSrc);
CComBSTR& operator+=(const CComBSTR& bstrSrc);
HRESULT AppendBSTR(BSTR p);
使用+ =运算符,您可以这样追加:
CComBSTR strSentence = OLESTR("Now is the time ");
// strSentence contains "Now is the time "
CComBSTR str11 (OLESTR("for all good men ");
// calls Append(const CComBSTR& bstrSrc);
strSentence.Append(str11);
// strSentence contains "Now is the time for all good men "
// calls Append(LPCOLESTR lpsz);
strSentence.Append((OLESTR("to come "));
// strSentence contains "Now is the time for all good men to come "
// calls Append(LPCSTR lpsz);
strSentence.Append("to the aid ");
// strSentence contains
// "Now is the time for all good men to come to the aid "
CComBSTR str12 (OLESTR("of their country"));
strSentence += str12; // calls operator+=()
// "Now is the time for all good men to come to
// the aid of their country"
此链接提供了更多相关信息:http://www.369o.com/data/books/atl/0321159624/ch02lev1sec3.html
答案 1 :(得分:1)
微软说:
CComBSTR
类是BSTR
的包装器,它是长度为前缀的字符串。
您必须使用CComBSTR::Append 或
bstr = CStringW(L" String2")+ bstr