I am not sure about Kenny's macros, however I suppose that you absolutely need to know the following: error codes have most significant bit set and render the whole value negative. "Standard" macros SUCCEEDED
and FAILED
test codes exactly for this.
HRESULT nValue = ...
if(SUCCEEDED(nValue)) {
// Not Error
}
Then for code brevity and readability you will want a macro that does both things together: tests for success/failure and either returns on error, or throws an exception. I suppose HR
macro in question does one of the two.
If you are going to use ATL, there are predefined macros of this kind already: ATLENSURE_SUCCEEDED
, ATLENSURE_THROW
etc. Microsoft decided to not document them though (I am not aware of a MSDN link to provide here).
Your HR
could be something like (depending on desired action - to throw or exit on error):
inline VOID HR(HRESULT nValue) { if(FAILED(nValue)) AtlThrow(nValue); }
or
#define HR(x) { HRESULT nValue = (x); if(FAILED(nValue)) return nValue; }
Also, to conveniently decode WIC and D2D HRESULT
s you might want to use this system tray helper app.