What#39;s the difference between BSTR and _bstr_t?(BSTR 和 _bstr_t 有什么区别?)
问题描述
谁能解释上面提到的类型之间的区别以及一些示例用法以清楚地解释两者之间的区别?
Can anyone explain the difference between the types mentioned above and some sample usage to clearly explain the difference between the two?
任何帮助将不胜感激!注意:这个问题是 this other question
Any help would be highly appreciated! Note: this question is a spin-off from this other question
推荐答案
BSTR 是 COM 使用的字符串数据类型.
BSTR is the string data type used with COM.
_bstr_t 是一个像智能指针一样工作的包装类,因此当变量被销毁或超出范围时,它将释放分配的内存._bstr_t 还具有引用计数,每次按值传递 _bstr_t 变量时都会增加(避免不必要的复制),并在不再使用时减少.每当所有引用都被销毁时,为字符串分配的内存就会被释放.
_bstr_t is a wrapper class that works like a smart pointer, so it will free the allocated memory when the variable is destroyed or goes out of scope. _bstr_t also has reference counting, which increases every time you pass the _bstr_t variable by value (avoiding unnecessary copy) and decrement when it is no longer used. Whenever all references are destroyed, the allocated memory for the string is freed.
BSTR 的替代品是 CComBSTR.它还管理 BSTR 的内存,但没有引用计数.
An alternative to BSTR is the CComBSTR. It also manages the memory for the BSTR, but has no reference counting.
这篇关于BSTR 和 _bstr_t 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:BSTR 和 _bstr_t 有什么区别?
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
