非主流字体下载:Windows核心编程(第五版)笔记 第一章 错误处理(Error Handling)
来源:百度文库 编辑:九乡新闻网 时间:2024/04/30 19:17:20
Windows核心编程
第一章 错误处理(Error Handling)
1.错误的表示
Windows在Winerr.h中定义了所有Win API的错误值。
一个错误值由三部分组成:Message ID, Message Text,一个数值。
如下:
// MessageId: ERROR_SUCCESS
// MessageText: The operation completed successfully.
#define ERROR_SUCCESS 0L
2.GetLastError/SetLastError/FormatMessage
GetLastError/SetLastError用于获取和设置函数的错误值。
FormatMessage用于将错误值翻译成相应的字符串。
如:0L翻译成 ”The operation completed successfully.”
头文件:#include
3.错误值的结构
错误值大于0代表函数调用成功。
Bits: 31-30 29 28 27-16 15-0
Contents
Severity
Microsoft/customer
Reserved
Facility code
Exception code
Meaning
0=Success
1 = Informational
2 = Warning
3 = Error
0 = Microsoft-defined code
1 = customer-defined code
Must be 0
The first 256 values are reserved by Microsoft
Microsoft/customer-defined code
4. $err,hr
在调用时可以在Windows Watch中能过$err,hr 查看最后一个线程的函数调用时的错误值