BSTR与wchar_t*的真正区别
spdia 2001-02-13 01:35:00 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的作用?