最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

winapi - MS-ERREF docs: HRESULT and NTSTATUS "N" bit - Stack Overflow

programmeradmin3浏览0评论

I am reviewing the MS-ERREF documentation for HRESULT error codes, which states the following for the N bit:

N (1 bit): If set, indicates that the error code is an NTSTATUS value (as specified in section 2.3), except that this bit is set.

The NTSTATUS section has this to say regarding the N bit:

N (1 bit): Reserved. MUST be set to 0 so that it is possible to map an NTSTATUS value to an equivalent HRESULT value, as specified in section 2.1, by setting this bit.

I'm trying to understand the "except that this bit is set" part in the HRESULT section's description of the N bit...

Is it saying that if the N bit is set in an HRESULT, then we should clear the bit and then reinterpret the error as an NTSTATUS?

I am reviewing the MS-ERREF documentation for HRESULT error codes, which states the following for the N bit:

N (1 bit): If set, indicates that the error code is an NTSTATUS value (as specified in section 2.3), except that this bit is set.

The NTSTATUS section has this to say regarding the N bit:

N (1 bit): Reserved. MUST be set to 0 so that it is possible to map an NTSTATUS value to an equivalent HRESULT value, as specified in section 2.1, by setting this bit.

I'm trying to understand the "except that this bit is set" part in the HRESULT section's description of the N bit...

Is it saying that if the N bit is set in an HRESULT, then we should clear the bit and then reinterpret the error as an NTSTATUS?

Share Improve this question asked Feb 15 at 14:22 Bill_StewartBill_Stewart 24.6k5 gold badges54 silver badges67 bronze badges 3
  • 1 Is it saying that if the N bit is set in an HRESULT, then we should clear the bit and then reinterpret the error as an NTSTATUS? - yes, exactly – RbMm Commented Feb 15 at 14:30
  • 1 Yes, the idea is that all error codes can be encoded as HRESULT values, where the N-bit identifies an NTSTATUS value stored as an HRESULT. – IInspectable Commented Feb 15 at 14:41
  • Thanks for the clarifications! That's what I thought it meant, but the "except that this bit is set" part of the sentence is awkwardly worded and confusing (at least to me). – Bill_Stewart Commented Feb 15 at 14:46
Add a comment  | 

1 Answer 1

Reset to default 0

Thanks to @RbMm and @IInspectable for the clarification on the Microsoft documentation: The answer is that the N bit in an HRESULT error code means "clear the N bit and interpret the result as an NTSTATAUS error code."

To help with error code analysis, I wrote an open-source console program to output details about Windows error codes, available here:

https://github/Bill-Stewart/ErrInfo/

It outputs the error code in binary, hexadecimal, and decimal numeric formats and uses FormatMessage to try to retrieve the message string related to the error code. (It's kind of an improved net helpmsg command.)

发布评论

评论列表(0)

  1. 暂无评论