Reputation: 1397
I'm new to COM. According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms221069(v=vs.85).aspx BSTR is a string with prefix. I am wondering what it the purpose for BSTR. In which case we have to use BSTR instead of string type? If someone could have an example please? Thanks
Upvotes: 0
Views: 331
Reputation: 170489
First of all, sometimes you have to use BSTR. For example, if you call a COM method and the callee expects a BSTR you'd rather not pass any other string type - otherwise they could call SysStringLen()
and run into undefined behavior. Use BSTR when an API descriptions says you should use BSTR.
Also BSTR
has these useful features:
Upvotes: 2
Reputation: 69687
BSTR
is standard string type in wide family of APIs:
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.
You use BSTR
when you have to, esp. when API you are using expects that you pass BSTR
; e.g. when certain COM interface method requires BSTR
argument. You use BSTR
or anything else at your discretion when you have choices.
Upvotes: 2