BSTR与wchar_t*的真正区别

spdia spdia 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
typedef /* [wire_marshal] */ OLECHAR __RPC_FAR *BSTR; in wtypes.h
typedef WCHAR OLECHAR; in wtypes.h
typedef wchar_t WCHAR; in winnt.h
typedef unsigned short wchar_t; in ctype.h


wchar_t wstrsource[16]=L"hello world";
BSTR bstrhello=::SysAllocString(wstrsource);
cout<<::SysStringLen(bstrhello)<<"\n";
cout<<::SysStringLen(wstrsource)<<"\n";

RESULT
11
2720172

wchar_t wstrsource[16]=L"hello\0world";
BSTR bstrhello=::SysAllocString(wstrsource);
cout<<::SysStringLen(bstrhello)<<"\n";
cout<<::SysStringLen(wstrsource)<<"\n";

RESULT
5
2720172

Q1:为什么会出现这样的结果?SysAllocString怎么判断字符串结束?'\0'会在"hello world"后自动添加?
Q2:BSTR与wchar_t *的区别?
Q3:wchar_t wstrsource[16]=L"hello\0world";中L的作用?
...全文
评论 4
收藏 已收藏
分享
返回顶部
spdia
VC/MFC 16,550 成员 421,606 内容