This is work in progress.

Windows / Error types

Windows Error Formats

Windows contains a vast number of error codes in various formats. This document explains the Win32, HRESULT, NTSTATUS, and LSTATUS error codes.

Win32

Win32 API error codes are possibly the most known code structure in Windows. These codes are used for various modules including the user-mode kernel modules (ntdll.dll).

All Windows error code should fit under 16-bit numbers between 0x0 (0) to 0xffff (65,535). However, some error codes may use a 32-bit number space with extended fields (ie, HRESULT).

HRESULT

HRESULT codes are used under the COM system

The table below denotes the structure of a HRESULT code.

31302928272616
SRCNXFacility
150
Code

Legend

HRESULT Facilities

The table below lists facilities defined in the MS-ERREF specification.

NameValueDescription
0FACILITY_NULLDefault
1FACILITY_RPCRPC subsystem
2FACILITY_DISPATCHCOM Dispatch
3FACILITY_STORAGEOLE Storage
4FACILITY_ITFCOM/OLE Interface management
7FACILITY_WIN32Win32
8FACILITY_WINDOWSWindows
9FACILITY_SECURITYSecurity API
10FACILITY_CONTROLControl mechanism
11FACILITY_CERTCertificate
12FACILITY_INTERNETWininet
13FACILITY_MEDIASERVERWindows Media Server
14FACILITY_MSMQMicrosoft Message Queue
15FACILITY_SETUPAPISetup API
16FACILITY_SCARDSmart-card subsystem
17FACILITY_COMPLUSCOM+
18FACILITY_AAFMicrosoft agent
19FACILITY_URT.NET CLR
20FACILITY_ACSAudit Collection Service
21FACILITY_DPLAYDirect Play
22FACILITY_UMIUbiquitous Memory-introspection service
23FACILITY_SXSSide-by-side (sxs) servicing
24FACILITY_WINDOWS_CEWindows CE
25FACILITY_HTTPHTTP
26FACILITY_USERMODE_COMMONLOGCommon Logging
31FACILITY_USERMODE_FILTER_MANAGERUser Mode Filter Manager
32FACILITY_BACKGROUNDCOPYBackground Copy
33FACILITY_CONFIGURATIONConfiguration Services
34FACILITY_STATE_MANAGEMENTState Management Services
35FACILITY_METADIRECTORYMicrosoft Identity Server
36FACILITY_WINDOWSUPDATEWindows update
37FACILITY_DIRECTORYSERVICEActive Directory
38FACILITY_GRAPHICSGraphics drivers
39FACILITY_SHELLUser shell
40FACILITY_TPM_SERVICESTrusted Platform Module services
41FACILITY_TPM_SOFTWARETrusted Platform Module applications
48FACILITY_PLAPerformance Logs and Alerts
49FACILITY_FVEFull Volume Encryption
50FACILITY_FWPFirewall Platform
51FACILITY_WINRMWindows Resource Manager
52FACILITY_NDISNetwork Driver Interface
53FACILITY_USERMODE_HYPERVISORUsermode Hypervisor components
54FACILITY_CMIConfiguration Management Infrastructure
55FACILITY_USERMODE_VIRTUALIZATIONUser Mode Virtualization Subsystem
56FACILITY_USERMODE_VOLMGRUser Mode Volume Manager
57FACILITY_BCDBoot Configuration Database
58FACILITY_USERMODE_VHDUser Mode Virtual Hard Disk
60FACILITY_SDIAGSystem Diagnostics
61FACILITY_WEBSERVICESWeb Services
80FACILITY_WINDOWS_DEFENDERWindows Defender
81FACILITY_OPCOpen Connectivity service

Some HRESULT codes, as exceptions, have the X bit set. They are listed below.

NameValue
0x0DEAD100TRK_S_OUT_OF_SYNC
0x0DEAD102TRK_VOLUME_NOT_FOUND
0x0DEAD103TRK_VOLUME_NOT_OWNED
0x0DEAD107TRK_S_NOTIFICATION_QUOTA_EXCEEDED
0x8DEAD01BTRK_E_NOT_FOUND
0x8DEAD01CTRK_E_VOLUME_QUOTA_EXCEEDED
0x8DEAD01ETRK_SERVER_TOO_BUSY

Converting Win32 error codes to an HRESULT code is done with thefollowing C macro.

#define FACILITY_WIN32 0x0007
#define __HRESULT_FROM_WIN32(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000)))

NTSTATUS

NTSTATUS error codes are typically used for low-level operations such as machine check exceptions, debugger API, and the SysWOW64 32-bit application layer, communicated from the WindowsNT kernel.

These codes are defined in Ntdef.h and have the following structure.

31 30292827 16
SevCNFacility
15 0
Code

Legend

NTSTATUS Severities

ValueNameDescription
0x0STATUS_SEVERITY_SUCCESSSuccess.
0x0STATUS_SEVERITY_SUCCESSSuccess.
0x1STATUS_SEVERITY_INFORMATIONALInformational.
0x2STATUS_SEVERITY_WARNINGWarning.
0x3STATUS_SEVERITY_ERRORError.

NTSTATUS Facilities

The table below lists facilities defined in the MS-ERREF specification.

NameValueDescription
1FACILITY_DEBUGGERWindows Debugger
2FACILITY_RPC_RUNTIMEWindows Remote Procedure Call Runtime
3FACILITY_RPC_STUBSWindows Remote Procedure Call Stub
4FACILITY_IO_ERROR_CODEInput/Output
7FACILITY_NTWIN32WindowsNT Win32
9FACILITY_NTSSPISecurity Support Provider Interface (SSPI)
10FACILITY_TERMINAL_SERVERWindows Terminal Server
11FACILTIY_MUI_ERROR_CODEMultilingual User Interface
16FACILITY_USB_ERROR_CODEUniversal Serial Bus
17FACILITY_HID_ERROR_CODEHumand Interface Device
18FACILITY_FIREWIRE_ERROR_CODEIEEE 1394 FireWire
19FACILITY_CLUSTER_ERROR_CODE
20FACILITY_ACPI_ERROR_CODEAdvanced Configuration and Power Interface
21FACILITY_SXS_ERROR_CODEWindows Side-by-Side
25FACILITY_TRANSACTIONWindows Kernel Transaction Manager (KTM)
26FACILITY_COMMONLOGWindows Common Log File System (CLFS)
27FACILITY_VIDEOWindows Media Foundation
28FACILITY_FILTER_MANAGERWindows Filter Manager (FltMgr.sys)
29FACILITY_MONITORWindows Monitor File
30FACILITY_GRAPHICS_KERNELWindows DirectX Graphics Kernel
32FACILITY_DRIVER_FRAMEWORKWindows Driver Framework (WDF)
33FACILITY_FVE_ERROR_CODEWindows Full Volume Encryption
34FACILITY_FWP_ERROR_CODEWindows Filtering Platform (WFP)
35FACILITY_NDIS_ERROR_CODEWindows Network Driver Interface Specification
53FACILITY_HYPERVISORWindows Hyper-V
54FACILITY_IPSECWindows IPSec

LSTATUS

The LSTATUS codes are legacy error codes used in some Windows functions. The 'L' in LSTATUS connotates the Windows LONG data type, defined in winreg.h as LONG under WinNT.h. The LONG data type is defined as the C long data type.

Functions returning LSTATUS codes, such as the low-level Windows Registry API (winreg.h), intially introduced in Window 3.1 (1992), and the Windows Shell API (Shlwapi.h), do not seem to set the thread's last error code (for example, using SetLastError), resulting in confusing GetLastError results.

These error codes can also be used directly for FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM.