开发者

ATL CString or_bstr_t?

In our COM project, we need to choose between best string class implementation so that BSTR (used for COM interfaces) and elegant开发者_开发技巧 string class like CString provides many string manipulation APIs.

Are there any better way to handle the strings and string operations so that it can be BSTR complaints as well as we can have naive CString operations?


Unortunately nothing realy elegant here. The best you can do is to use CString::AllocSysString() and you better use a BSTR wrapper like CComBSTR or _bstr_t to manage the resulting BSTR lifetime. See this question for how it usually done.


CString has AllocSysString function: http://msdn.microsoft.com/en-us/library/za1865s1%28VS.80%29.aspx

You can use it before calling COM methods.

You can use _bstr_t::Attach to create _bstr_t instance from CString::AllocSysString call, in this case you don't need to care about BSTR release.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜