Explaining the declaration/definition of HRESULT

Agnel Kurian picture Agnel Kurian · Dec 31, 2009 · Viewed 9.9k times · Source

I just looked at the definition of HRESULT in VS2008. WinNT.h has the following line:

typedef __success(return >= 0) long HRESULT;

What exactly does it mean? It doesn't even look like C or C++ to my untrained eye

Answer

jason picture jason · Dec 31, 2009

It is an annotation. In short,

__success(expr)

means that expr describes the conditions under which a function is considered to have succeeded. For functions returning HRESULT, that condition is that the return value (since HRESULT is a long) is non-negative. All functions returning HRESULT have this annotation applied to them because of this typedef.

Probably way more detail than you will ever want in MSDN on SAL Annotations, The Evolution of HRESULT From Win32 and Success and Failure Annotations.