In listings of Win32 error codes, each error has three components:
- The numeric error code
- A descriptive message
- An identifier consisting of capitalized words separated by underscores
According to the documentation, the term "message identifier" refers to the descriptive message, but it doesn't say what the term is for the capitalized error name, and I haven't been able to find that anywhere. These identifiers appear to be analogous to what's called the "Error Id" in a PowerShell ErrorRecord object, but googling for "win32 error id" and "win32 error identifier" didn't lead to an answer.
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 __________?
Also, how can this text value be determined, given an error code? I can easily determine the message identifier associated with a given error code like this:
string MessageIdentifier = new Win32Exception(ErrorCode).Message;
However, the Win32Exception class doesn't appear to have a property that corresponds to these capitalized error names (analogous to the ErrorRecord class's ErrorId property).
In some listings I've seen these kinds of identifiers referred to as "constants", but if they're constants, where are they defined/enumerated and how do you access them from a program?
You are wrong on the last two points.
4
is both the error code and the message identifier, per the same documentation you linked to:The system cannot open the file.
is the message text that belongs to message identifier4
. That text is reported byFormatMessage()
andWin32Exception.Message
.ERROR_TOO_MANY_OPEN_FILES
is just a human-readable#define
in winerror.h in the Win32 SDK:There is no function in either the Win32 API or .NET to return the text
ERROR_TOO_MANY_OPEN_FILES
given the error code4
. You would have to write your own lookup code if you need that functionality, as demonstrated by this pinvoke.net example:WINERROR (Constants)