views:

21

answers:

0

In my COM component I need to translate all errors into the most suitable HRESULT values possible. Currently if I call some RPC interface method (I call a MIDL-generated stub that in turn calls NdrClientCall2()) and the call fails I return E_FAIL which is not very convenient.

There's so-called facility in HRESULT. Can I use this?

I tried to do the following:

HRESULT RpcStatusToHresult( RPC_STATUS status )
{
     if( status <= 0 ) {
         return status;
     }
     return ( status & 0x0000FFFF ) | (FACILITY_RPC << 16) | 0x80000000;
}

Will this properly translate RPC_STATUS to meaningful HRESULTs?