5

In the Windows header file WinNT.h, HRESULT is defines as follows:

typedef __success(return >= 0) long HRESULT;

Doing some research I learned that the "__success" macro is part of the Microsoft source code annotation language SAL and is defined in sal.h. But for the life of me I can't figure out what it does or how it does it.

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
  • Seems that this question has already been posted: http://stackoverflow.com/questions/1985521/explaining-the-declaration-definition-of-hresult __success expands to nothing so it doesn't affect the code. While it may help Microsoft's analysis tools, it really really messes up the readability of the code, in my opinion. – Sabuncu Nov 18 '10 at 08:29

1 Answers1

5

This blog post on MSDN explains exactly what __success means: it indicates that a function succeeded if it returns a HRESULT value >= 0.

Annotations are just a way of describing something about a piece of code - by themselves, they don't "do" anything, but it's possible to have external tools verify the semantics of such annotations.

Billy
  • 96
  • 4
casablanca
  • 69,683
  • 7
  • 133
  • 150
  • I had read the blog post prior to posting my question. The blog is not well-written (suddenly starts talking about a scanner without any definition) and I really could not understand it. Specifically, what happens if the return code is less than zero? – Sabuncu Nov 17 '10 at 19:07
  • @Toddintr: As I mentioned, the annotations by themselves don't change the way your program behaves. But there are tools (see http://blogs.msdn.com/b/michael_howard/archive/2006/05/19/602077.aspx) that can use these annotations to inspect your code and warn you of possibly incorrect usage. – casablanca Nov 17 '10 at 20:39
  • FWIW, the link to the MSDN blog post is dead. – R Sahu May 12 '20 at 17:25