Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explaining the declaration/definition of HRESULT

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

like image 909
Agnel Kurian Avatar asked Dec 31 '09 13:12

Agnel Kurian


2 Answers

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.

like image 75
jason Avatar answered Nov 06 '22 06:11

jason


This MS-specific keyword is for static code analysis tools.

It helps by hint on how to check whether function's return code means that it completed the task properly.

For instance, see http://msdn.microsoft.com/en-us/library/aa468782.aspx

like image 21
Pavel Radzivilovsky Avatar answered Nov 06 '22 06:11

Pavel Radzivilovsky