How to translate RPC_STATUS to HRESULT?

In my COM component, I need to translate all errors into the most appropriate values HRESULT. Currently, if I call some method of the RPC interface (I call the MIDL called stub, which in turn calls NdrClientCall2 () ), and the call does not return E_FAIL, which is not very convenient.

There is the so-called object 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 translate RPC_STATUSto meaningful HRESULTs?

+3
source share
2 answers

RpcStatusToHresult () MAKE_HRESULT (1, FACILITY_RPC, ). HRESULT_FROM_WIN32 () MAKE_HRESULT (1, FACILITY_WIN32, ).

, , , , , , FormatMessage(), - , .

+3

FWIW, , HRESULT_FROM_WIN32

+2

Source: https://habr.com/ru/post/1752235/


All Articles