CString char* BSTR

BSTR

COM是一种跨 编程语言的平台,需要提供语言无关的 数据类型。多数 编程语言有自己的字符串表示。
●C++  字符串是以0结束的ASCII或Unicode字符 数组
●Visual Basic 字符串是一个ASCII字符 数组加上表示长度的前缀。
●Java字符串是以0结束的Unicode字符 数组
需要定义一种通用的字符串类型,可以很容易的匹配到不同 编程语言 C++ 中,就是 BSTR
 

1.  char*转换成BSTR

  方法一,使用SysAllocString等API函数。例如:

BSTR bstrText = ::SysAllocString(L"Test"); 

 

2 . CString转换成BSTR

  通常是通过使用CStringT::AllocSysString来实现。例如:

CString str("This is a test"); 
BSTR bstrText = str.AllocSysString(); 
… 
SysFreeString(bstrText); // 用完释放 

猜你喜欢

转载自yangbinfx.iteye.com/blog/1894195
今日推荐