First, you donβt need to do anything at all if you only need to read the contents. The BSTR type is already a pointer to a wchar_t array with zero completion. In fact, if you check the headers, you will find that the BSTR is essentially defined as:
typedef BSTR wchar_t*;
Thus, the compiler cannot distinguish between them, even if they have different semantics.
There are two important questions.
BSTR must be unchanged. You should never modify the contents of a BSTR after it has been initialized. If you βchange it,β you need to create a new one, assign a new pointer and release the old one (if you own it).
[ UPDATE : this is not true; Sorry! You can change the BSTR in place; I very rarely needed.]
BSTRs are allowed to contain embedded null characters, while traditional C / C ++ strings are not.
BSTR , BSTR NULL, BSTR, wchar_t, (wcscpy, ..) . , . BSTR, wchar_t. .
, NULL. , BSTR. - :
UINT length = SysStringLen(myBstr);
wchar_t *myString = new wchar_t[lenght+1];
wcscpy(myString, myBstr);
delete myString;
BSTR, SysStringLen() . :
CComBString use .Length();
_bstr_t use .length();
. - , :
"Eric [Lippert] BSTR"
UPDATE: strcpy() wcscpy()