You should take care of everything BSTRexcept those that you actually pass as the "out" parameter. BSTRyou cannot free yourself - the caller is responsible for freeing him, and your code is responsible for all the others BSTRthat he could allocate.
BSTR, -, ATL::CComBSTR _bstr_t BSTR ( , ). , , , , BSTR .
:
HRESULT YourFunction( BSTR* result )
{
if( result == 0 ) {
return E_POINTER;
}
int internalStateValue = getState();
if( internalStateValue > 0 ) { // first case
*result = SysAllocString( "positive" );
} else if( internalStateValue < 0 ) { //second case
*result = SysAllocString( "negative" );
} else { //default case
*result = SysAllocString( "zero" );
}
return S_OK;
}