解释 HRESULT 的声明/定义
我刚刚看了VS2008中HRESULT
的定义。 WinNT.h 有以下行:
typedef __success(return >= 0) long HRESULT;
它到底是什么意思?在我未经训练的眼中,它甚至看起来都不像 C 或 C++
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它是一个注释。简而言之,
意味着
expr
描述了函数被视为成功的条件。对于返回HRESULT
的函数,该条件是返回值(因为HRESULT
是long
)为非负数。由于此typedef
,所有返回HRESULT
的函数都会应用此注释。可能比 MSDN 中关于 SAL 注释的信息更详细, HRESULT 从 Win32 的演变 和成功和失败注释 。
It is an annotation. In short,
means that
expr
describes the conditions under which a function is considered to have succeeded. For functions returningHRESULT
, that condition is that the return value (sinceHRESULT
is along
) is non-negative. All functions returningHRESULT
have this annotation applied to them because of thistypedef
.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.
Windows API 在这里使用宏黑魔法来创建自己的编程语言。你需要继续挖掘。
__success 定义为:
sal.h:
... 而 inner_success 定义为:
... 没什么。因此 HRESULT typedef 简化为:
The Windows API is using macro black magic here to create thier own programming language. You needed to keep digging.
__success is defined as:
sal.h:
...and inner_success is defined as:
...which is nothing. So the HRESULT typedef reduces to:
这个 MS 特定的关键字用于静态代码分析工具。
它通过提示如何检查函数的返回代码是否意味着它正确完成了任务来提供帮助。
例如,请参阅 http://msdn.microsoft.com/en-us/库/aa468782.aspx
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