gpt4 book ai didi

c# - 调用的 Win32 错误代码的大写文本标识符是什么?给定错误代码,如何以编程方式确定它们?

转载 作者:行者123 更新时间:2023-11-30 20:43:44 25 4
gpt4 key购买 nike

listings of Win32 error codes ,每个错误都包含三个组成部分:

  • 数字错误代码
  • 描述性信息
  • 由下划线分隔的大写单词组成的标识符

根据 the documentation ,术语“消息标识符”指的是描述性消息,但它没有说明大写错误名称的术语是什么,而且我在任何地方都找不到。这些标识符似乎类似于 PowerShell ErrorRecord 对象中所谓的“错误 ID”,但谷歌搜索“win32 错误 ID”和“win32 错误标识符”没有找到答案。

例如,在下面的错误中:

ERROR_TOO_MANY_OPEN_FILES

4 (0x4)

The system cannot open the file.

  • 4错误代码
  • 系统无法打开文件。消息标识符
  • ERROR_TOO_MANY_OPEN_FILES 是 __________?

另外,给定一个错误代码,如何确定这个文本值?我可以像这样轻松确定与给定错误代码关联的消息标识符:

string MessageIdentifier = new Win32Exception(ErrorCode).Message;

然而,the Win32Exception class似乎没有对应于这些大写错误名称的属性(类似于 ErrorRecord 类的 ErrorId 属性)。

在一些列表中,我看到这些类型的标识符被称为“常量”,但如果它们是常量,它们在哪里定义/枚举以及如何从程序访问它们?

最佳答案

For example, in the following error:

ERROR_TOO_MANY_OPEN_FILES
4 (0x4)
The system cannot open the file.

4 is the error code.
The system cannot open the file. is the message identifier.
ERROR_TOO_MANY_OPEN_FILES is the __________?

最后两点你错了。 4错误代码消息标识符,根据相同的documentation你链接到:

All Win32 error codes MUST be in the range 0x0000 to 0xFFFF, although Win32 error codes can be used both in 16-bit fields (such as within the HRESULT type specified in section 2.1) as well as 32-bit fields. Most values also have a default message defined, which can be used to map the value to a human-readable text message; when this is done, the Win32 error code is also known as a message identifier.

系统无法打开文件。是属于消息标识符4的消息文本。该文本由 FormatMessage() 报告和 Win32Exception.Message .

ERROR_TOO_MANY_OPEN_FILES 只是 Win32 SDK 中 winerror.h 中人类可读的 #define:

//
// MessageId: ERROR_TOO_MANY_OPEN_FILES
//
// MessageText:
//
// The system cannot open the file.
//
#define ERROR_TOO_MANY_OPEN_FILES 4L

在给定错误代码 4 的情况下,Win32 API 或 .NET 中都没有返回文本 ERROR_TOO_MANY_OPEN_FILES 的函数。如果您需要该功能,则必须编写自己的查找代码,如这个 pinvoke.net 示例所示:

WINERROR (Constants)

int errorCode = 4; //Microsoft.Win32.Interop.ResultWin32.ERROR_TOO_MANY_OPEN_FILES
string identName = Microsoft.Win32.Interop.ResultWin32.GetErrorName(errorCode);
// returns "ERROR_TOO_MANY_OPEN_FILES"

关于c# - 调用的 Win32 错误代码的大写文本标识符是什么?给定错误代码,如何以编程方式确定它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30203717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com