Expand description
§🦀 winresult - windows result codes 🦀
Debug-friendly types for windows result codes.
§Why?
-
u32
error codes are annoying todbg!(...)
.winresult
has awesomeDebug
impls. -
u32
error codes are annoying to view in your debugger.winresult
has awesome *.natvis files. Usenatvis-pdbs
! -
typoing
ERROR_WHATEVER
in amatch
is a mere warning.ERROR::WHATEVER
is a hard error.
(I’d still use#![deny(unreachable_patterns)]
anyways.) -
ERROR_INVALID_FUNCTION
==S_FALSE
(==1
.) Lame! -
ERROR_FILE_NOT_FOUND
(2) is a mess. A function orGetLastError
might return:label value notes ERROR_FILE_NOT_FOUND
0x00000002
Not an HRESULT
(would be “successful”)HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
0x80070002
hresult.info “incorrectly” labels ERROR_*
as thisD3D10_ERROR_FILE_NOT_FOUND
0x88790002
Different facility, same code D3D11_ERROR_FILE_NOT_FOUND
0x887C0002
Different facility, same code -
ERROR_*
is a mixture ofHRESULT
s and non-HRESULT
s. Can you keep them straight? No. No you cannot. Stop lying.
§Types
min | max | type | notes |
---|---|---|---|
0 | 0xFFFF | ErrorCode | |
0 | 0x7FFFFFFF | HResultSuccess | |
0x80000000 | 0xFFFFFFFF | HResultError | |
0 | 0xFFFFFFFF | HResult | HResultSuccess | HResultError |
0 | 0xFFF | Â Â HResultFacilityMicrosoft | |
0 | 0xFFFFFFFF | NtStatus | SuccessNtStatus | ErrorNtStatus |
0 | 0xFFF | Â Â NtStatusFacilityMicrosoft | |
0 | 4 | Â Â NtStatusSeverity | |
0 | 0xFFFFFFFF | WaitCode | mostly <= 0x102 |
0 | 0xFFFFFFFF | ErrorHResultOrCode | ErrorCode | HResultError |
§Modules of Note
mod | types |
---|---|
ERROR | ErrorCode, HResultError, and HResultSuccess(!) |
FACILITY | HResultFacilityMicrosoft, NtStatusFacilityMicrosoft |
STATUS | NtStatus |
STATUS::SEVERITY | NtStatusSeverity |
WAIT | WaitCode |
§Buggy Bitwise Comparisons to Forbid
left | right | why |
---|---|---|
ErrorCode | HResultError | never true , non-overlapping ranges, need to add or remove facility |
ErrorCode | HResultSuccess | ERROR_INVALID_FUNCTION == S_FALSE , need to add or remove facility |
ErrorCode | HResult | ERROR_INVALID_FUNCTION == S_FALSE , need to add or remove facility |
ErrorCode | WaitCode | ERROR_INVALID_FUNCTION == WAIT_OBJECT_0+1 |
*Success | *Error* | never true except by accident |
§Conversions
- HResultSuccess → HResult
- (HResultFacilityMicrosoft, ErrorCode) → HResultError → HResult
Modules§
- APPMODEL
- WinRT / UWP AppModel
- APPX
- APPX package
- BT
- Background Task
- CACHE
- Remote Desktop Protocol Bitmap Cache?
- CAT
- COM Categories
- CERT
- Certificates (for e.g. HTTPS etc.)
- CERTSRV
- Certificate Server (for e.g. Certificate Authority validation, etc.)
- CLASS
- COM Class
- CLIPBRD
- Clipboard
- CO
- COM
- COMADMIN
- COM Admin / Catalog
- COMQC
- COM+ Queued Components Protocol
- CONTEXT
- DCOM Context?
- CONVER
T10 - CRYPT
- CS
- D3D
- Direct3D
- D3D10
- Direct3D 10+
- D3D11
- Direct3D 11+
- D3D12
- Direct3D 12+
- D3DERR
- Direct3D Errors
- D3DOK
- Direct3D
- D3DXERR
- D3DX Errors
- D3DXFERR
- D3DX
.X
file type errors - DATA
- OLE / Clipboard Stuff?
- DCOMPOSITION
- DirectComposition
- DIGSIG
- Digital Signature
- DISP
- IDispatch
- DNS
- Domain Name Services
- DRAGDROP
- Drag and Drop
- DV
- OLE / Data Values / Clipboard Stuff?
- DWM
- Display Window Manager (desktop rendering composition)
- DWRITE
- DirectWrite
- DXCORE
- DirectX
- DXGI
- DXGI
- E
- Errors Codes. Typically HResultErrors.
- EAS
- Exchange ActiveSync
- ERROR
- Error Codes. Mostly a mixture of HResultErrors and ErrorCodes.
submodules:
CLOUD_FILE,
CLUSTER,
DBG,
DS,
EVT,
GRAPHICS,
IPSEC,
MRM,
MUI,
NDIS,
PRI_MERGE,
SECUREBOOT,
SERVICE,
SVHDX,
SXS,
SXS::XML,
VHD,
WMI
Note thatERROR::SUBCATEGORY::CODE
is also generally exported asERROR::SUBCATEGORY_CODE
, although the latter is hidden from the docs to reduce clutter. - EVENT
- COM Events
- FA
- FACILITY
- FACILITY_* Values for HResults and NtStatuses.
pub mod FACILITY::HRESULT::*, FACILITY::NTSTATUS::*; - FVE
- Full Volume Encryption / Bitlocker
- FWP
- Windows Filtering Platform
- GCN
- Host Computer Network
- HCN
- Host Computer Network
- HCS
- Host Compute System
- HSP
- HTTP
- WinINet / WinHTTP
- INET
- WinINet
- INPLACE
- INPUT
- IORING
- I/O Ring
- JSCRIPT
- MEM
- MENROLL
- Mobile Device Management (MDM) Enrollment
- MK
- MSDTC
- MSSIPOTF
- NAP
- OLE
- “Object Linking and Embedding”
- OLEOBJ
- “Object Linking and Embedding”
- ONL
- PEER
- PEERDIST
- Peer Distribution
- PERSIST
- PLA
- Performance Logs and Alerts
- PRESENTATION
- REGDB
- COM+ registration database
- RO
- WinRT COM
- S
- Success codes
- SCARD
- Smart Card
- SCHED
- Task Scheduler
- SDIAG
- SEC
- SPAPI
- SQLITE
- SQLite
- STATEREPOSITORY
- STATUS
- [docs.microsoft.com] NtStatus errors, warnings, and other codes (for use in e.g. Kernel / Drivers)
- STG
- Structured Storage?
- STORE
- Microsoft Store?
- TBS
- TBSIMP
- TPC
- Tablet PC
- TPM
- Trusted Platform Module (1.2)
- TPMAPI
- Trusted Platform Module
- TPM_20
- Trusted Platform Module 2.0
- TRUST
- Certificate Trust
- TYPE
- COM Type Libraries
- UI
- UTC
- Universal Telemetry Client (UTC) data in Event Tracing for Windows (ETW) traces.
- VIEW
- VM_
SAVED_ STATE_ DUMP - WAIT
- [docs.microsoft.com] WAIT_* values returned by various WaitFor* and other win32 functions.
- WEB
- WinINet / WinHTTP
- WEP
- Wired Equivalent Privacy
- WER
- Windows Error Reporting
- WHV
- Windows Hypervisor Platform
- WININET
- WinINet
- WPN
- Windows Push Notifications?
- WS
- Windows Web Services
- WSA
- WinSock
- XACT
- Cross-platform Audio Creation Tool (XACT)
- XAUDIO2
- XAudio 2
- XENROLL
- Pre-Vista Certificate Enrollment Control
Structs§
- Error
Code - [docs.microsoft.com] ERROR_* values that aren’t HRESULTs (but might be implicitly convertable)
- ErrorH
Result OrCode - [docs.microsoft.com] HResultError or ErrorCode
- HResult
- [docs.microsoft.com] HRESULT
- HResult
Error - [docs.microsoft.com] Error HRESULT
- HResult
Facility Microsoft - [docs.microsoft.com]
FACILITY_* values corresponding to Microsoft (non-customer)
HRSEULT
s. - HResult
Success - [docs.microsoft.com] Success HRESULT
- NtStatus
- [docs.microsoft.com] NTSTATUS
- NtStatus
Facility Microsoft - [docs.microsoft.com]
FACILITY_* values corresponding to Microsoft (non-customer)
NTSTATUS
es. - NtStatus
Severity - [docs.microsoft.com] NtStatus::Sev
- Wait
Code - [docs.microsoft.com] WAIT_* values returned by various WaitFor* and other win32 functions.