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 有什么区别?


基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01