My COM server implemented in Visual C++ uses a ton of other C++ code. That other C++ code sometimes wraps code in __try
-__except
and translates structured exceptions into custom C++ exceptions. This part I cannot change.
No method of my COM server should let those exceptions propagate through the COM boundary so it has to catch and translate them into HRESULT
s. Those custom C++ exceptions contain the original error code which was obtained during translation - it's something like EXCEPTION_ACCESS_VIOLATION
. The question is how I craft an appropriate HRESULT
value so that the client has as much information as possible as to what happened (and perhaps decide to restart the server (and itself in case of inproc) after seeing an access violation).
Suppose it was EXCEPTION_ACCESS_VIOLATION
which is defined in WinBase.h
#define EXCEPTION_ACCESS_VIOLATION STATUS_ACCESS_VIOLATION
and the latter is defined in WinNT.h
#define STATUS_ACCESS_VIOLATION ((DWORD)0xC0000005L)
I could use HRESULT_FROM_WIN32()
to translate that code into HRESULT
assuming that it was a Win32 error in the first place.
Do I use HRESULT_FROM_WIN32()
here or do I use any other way to do the translation?