Reputation:
The MSDN article just says:
Return Value
S_OK on success, or any standard HRESULT error value.
However, my guess is that E_OUTOFMEMORY is the only feasible error return since NULL is valid input and an invalid memory location will just throw an access violation (hopefully).
So. Are there any other possible HRESULTS from this method?
Note: The following all return S_OK:
CComBSTR bstr;
bstr.AssignBSTR(NULL);
bstr.AssignBSTR(SysAllocString(L"")); //clearly a leak, abbreviated example...
bstr.AssignBSTR(SysAllocString(L"HI"));
Bottom Line: Is the following good practice (and why do I often see other implementations?):
class foo {
public:
STDMETHOD(put_Bar)(BSTR p);
private:
CComBSTR m_bstrBar
};
STDMETHODIMP foo::put_Bar( BSTR p)
{
return m_bstrBar.AssignBSTR(p);
}
Upvotes: 0
Views: 305
Reputation: 941675
Yes, E_OUTOFMEMORY is it in this very specific case. You can see the source code in vc/atlmfc/include/atlcomcli.h
This is otherwise similar to asking for exception specifications. Doesn't work, COM methods can return any error code. Weird ones too when the call is marshaled out of process or across a network.
Upvotes: 2