BSTR

A BSTR (Basic string or binary string) is a string data type that is used by COM, Automation, and Interop functions. Use the BSTR data type in all interfaces that will be accessed from script.

C++

 

typedef WCHAR OLECHAR;

typedef OLECHAR* BSTR;

typedef BSTR* LPBSTR;

 

Remarks

A BSTR is a composite data type that consists of a length prefix, a data string, and a terminator. The following table describes these components.

Item

Description

Length prefix

A four-byte integer that contains the number of bytes in the following data string. It appears immediately before the first character of the data string. This value does not include the terminating null character.

Data string

A string of Unicode characters. May contain multiple embedded null characters.

Terminator

Two null characters.

 
 

A BSTR is a pointer. The pointer points to the first character of the data string, not to the length prefix.

BSTRs are allocated using COM memory allocation functions, so they can be returned from methods without concern for memory allocation.

The following code is incorrect:

BSTR MyBstr = L"I am a happy BSTR";

This code builds (compiles and links) correctly, but it will not function properly because the string does not have a length prefix. If you use a debugger to examine the memory location of this variable, you will not see a four-byte length prefix preceding the data string.

Instead, use the following code:

BSTR MyBstr = SysAllocString(L"I am a happy BSTR");

A debugger that examines the memory location of this variable will now reveal a length prefix containing the value 34. This is the expected value for a 17-byte single-character string that is converted to a wide-character string through the inclusion of the "L" string modifier. The debugger will also show a two-byte terminating null character (0x0000) that appears after the data string.

If you pass a simple Unicode string as an argument to a COM function that is expecting a BSTR, the COM function will fail.

Requirements

Header

WTypes.h

最新文章

  1. react 调用 native 的callShareAllFunc()方法,实现分享
  2. 史上最强防火墙iptables
  3. bzoj2716: [Violet 3]天使玩偶
  4. Linux学习方法
  5. 查找表或其他对象在某个Server上的存在
  6. 【24】若所有参数皆需类型转换,请为此采用non-members函数
  7. .Net类型与JSON的映射关系
  8. 怎么做fastreport使用离线数据源
  9. HDU-1996-汉诺塔VI
  10. TweenMax.js
  11. Ext 日期格式化
  12. 斯坦福大学公开课机器学习:advice for applying machine learning - deciding what to try next(设计机器学习系统时,怎样确定最适合、最正确的方法)
  13. 2)实现github自动登陆获取信息
  14. LeetCode(54):螺旋矩阵
  15. Java 容器源码分析之1.7HashMap
  16. 000 Jquery的Hello World程序
  17. apache的错误日志分析
  18. L3-014 周游世界 (30 分)
  19. PLSQL优化基础和性能优化 (学习总结)
  20. strptime和strptime函数理解

热门文章

  1. mysql 通过cmd 在命令行创建数据库
  2. Template(Updating)
  3. Kolibri v2.0-Buffer Overflow成功复现
  4. hdu 1698 线段树 成段更新
  5. 【10.26校内测试】【状压?DP】【最小生成树?搜索?】
  6. bzoj 2460 拟阵+判线性相关
  7. Codeforces Round #353 (Div. 2) C. Money Transfers 数学
  8. C# 高级编程9 第30章MEF C#可扩展编程之MEF第一章
  9. 通过adb把apk安装到系统分区
  10. lol匹配算法