BSTR到CStringT的转换 [英] BSTR to CStringT conversion

查看:87
本文介绍了BSTR到CStringT的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何将CStringT变量的内容分配给BSTR或CComBSTR变量,但是我应该如何去做呢?我有一个包含BSTR参数的C ++ Com方法.我想将该参数的内容分配给CStringT,以便能够在转换回BSTR并返回之前使用CStringT的字符串操作方法.如何初始化此CString并进行赋值?如果有的话,请发送一个代码示例.

I know how to assign the contents of a CStringT variable to a BSTR or CComBSTR variable, but how do I go the other way? I have a C++ Com method that includes a BSTR argument. I want to assign the contents of that argument to CStringT, to be able to use CStringT''s string manipulation methods before converting back to BSTR and returning. How do I initialize this CString and make the assignment? Please send a code example, if you have one. Thanks!

推荐答案

本文介绍了如何做到这一点(以及其他类似的转换):

This article shows how to do that (as well as other similar conversions):

  • Guide to BSTR and C String Conversions[^]
  • http://www.flounder.com/cstring.htm[^]


CAtlString str(_T(这是我的字符串!"));
BSTR bstr = str.AllocSysString();
我认为这对您有帮助.
CAtlString str(_T("This is my string!"));
BSTR bstr = str.AllocSysString();
i think this will help u.


这篇关于BSTR到CStringT的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆