I knew from the ATL Internals book that BSTR is different from OLECHAR *, and there are CComBSTR and CString for BSTR.
According to the MSDN Allocation and Release of Memory for BSTR , I knew the responsibility of managing memory for the caller / called party.
Take this line from MSDN,
HRESULT CMyWebBrowser::put_StatusText(BSTR bstr)
I still don't know how to properly handle bstrin my implementation. Since I still have a basic question for BSTR, should I consider it bstras a value (e.g. int) or as a reference (e.g. int *), at least at the border of the COM interface.
I want to convert BSTR to CString / CComBSTR in my implementation as quickly as possible. Value or reference semantics will be a completely different case for conversion. I dug in CComBSTR.Attach, CComBSTR.AssignBSTR etc. But the code cannot solve my doubts.
MSDN CComBSTR.Attach has some piece of code, I feel that it is erroneous as it does not obey Allocation and freeing memory for BSTR . ATL Internals said that SetSysString "will free the original BSTR passed to", if I used it, it would violate the BSTR argument convention, like CComBSTR.Attach.
In general, I want to use CString to handle the raw BSTR in the implementation, but I donβt know the right way ... I wrote some simple working codes in my projects, but I'm always nervous, I know how much I am right.
HRESULT CMyWebBrowser::put_StatusText(BSTR bstr)
{
CString str1;
CString str2;
CComBSTR cbstr1;
cbstr1.AssignBSTR(bstr);
CComBSTR cbstr2;
cbstr2.Attach(bstr);
}