views:

48

answers:

1

There's RpcRaiseException() dunction in MS RPC runtime to indicate errors that occur during an RPC call either on the server side or in a pipe callback on the client side. The RPC_STATUS passed into RpcRaiseError() is propagated to the site of the RPC call.

The problem is how do I choose the RPC_STATUS value?

Say in a pipe pull() callback I read data from IStream* and feed that data into the pipe. Now IStream::Read() returns an HRESULT indicating an error and I need to call RpcRaiseException() to interrupt the call.

What value do I pass?

A: 

If you have an API which can fail, why not have the API return the failure code as the return value for the API?

If you DO want to use RpcRaiseException, the exception will be propogated as an exception to the client side so the exception code will show up as the RpcExceptionCode in the RpcExcept handler on the client side.

Larry Osterman
Do you mean I simply pass the HRESULT value into RpcRaiseError(). Otherwise I have no ways to indicate that something went wrong in the pipe callback.
sharptooth
No, you define your API as returning a HRESULT. Then you simply return the error code from the server.
Larry Osterman
sharptooth: Note that I edited my answer for clarity and to correct an incorrect assumption.
Larry Osterman
I see. But I just can't do anything like that in a callback without inventing a huuuge wheel.
sharptooth
sharptooth - what happens when you just raise the Win32 error code as an exception? The RPC server performing the callback *should* have wrapped the callback with an RpcTryExcept/RpcExcept handler to protect against transient RPC failures.
Larry Osterman