Convert from Wstring to CComBstr

徘徊边缘 提交于 2019-12-13 07:09:44

问题


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


回答1:


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());


来源:https://stackoverflow.com/questions/8645068/convert-from-wstring-to-ccombstr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!