12 unstable releases (4 breaking)

0.4.1 Oct 6, 2025
0.3.4 May 19, 2025
0.3.2 Mar 18, 2025
0.2.0 Jul 3, 2024
0.1.0 Feb 22, 2024

#416 in Windows APIs

Download history 3194310/week @ 2025-10-27 3151568/week @ 2025-11-03 3007255/week @ 2025-11-10 3340686/week @ 2025-11-17 2389564/week @ 2025-11-24 2732350/week @ 2025-12-01 3347101/week @ 2025-12-08 3241429/week @ 2025-12-15 1732748/week @ 2025-12-22 1643025/week @ 2025-12-29 3438473/week @ 2026-01-05 3866861/week @ 2026-01-12 4070891/week @ 2026-01-19 4152737/week @ 2026-01-26 4166353/week @ 2026-02-02 4432812/week @ 2026-02-09

17,043,630 downloads per month
Used in 19,903 crates (29 directly)

MIT/Apache

33KB
699 lines

Windows error handling

The windows-result crate provides efficient Windows error handling and propagation with support for Win32, COM, and WinRT APIs.

Start by adding the following to your Cargo.toml file:

[dependencies.windows-result]
version = "0.4"

Use the HRESULT, Error, and specialized Result types as needed:

use windows_result::*;

const S_OK: HRESULT = HRESULT(0);
const ERROR_CANCELLED: u32 = 1223;
const E_CANCELLED: HRESULT = HRESULT::from_win32(ERROR_CANCELLED);

fn main() -> Result<()> {
    S_OK.ok()?;
    let e = Error::new(E_CANCELLED, "test message");
    assert_eq!(e.code(), E_CANCELLED);
    assert_eq!(e.message(), "test message");
    Ok(())
}

Dependencies