Convert from Wstring to CComBstr

2019-09-08 15:28发布

Please suggest me methods for converting from wstring to CComBstr.

I tried to convert like following but it is failing

CComBSTR BstrAddress(strID); // strID is wstring type

I am getting error as "cannot convert parameter 1 from 'std::wstring' to 'int'" Please help me regarding this

标签: c++ wstring bstr
1条回答
仙女界的扛把子
2楼-- · 2019-09-08 16:02

These are constructors of CComBSTR class:

CComBSTR( ) throw( ); 
CComBSTR(
   const CComBSTR& src 
);
CComBSTR(
   REFGUID guid 
);
CComBSTR(
   int nSize 
);
CComBSTR(
   int nSize,
   LPCOLESTR sz 
);
CComBSTR(
   int nSize,
   LPCSTR sz 
);
CComBSTR(
   LPCOLESTR pSrc 
);
CComBSTR(
   LPCSTR pSrc 
);

MSDN

So, you could convert like this:

CComBSTR BstrAddress(strID.size(), strID.data());
查看更多
登录 后发表回答