51 breaking releases

new 0.59.0 Jan 7, 2025
0.58.0 Jul 3, 2024
0.57.0 Jun 7, 2024
0.54.0 Feb 27, 2024
0.0.0 Jan 15, 2019

#1 in Windows APIs

Download history 823902/week @ 2024-09-22 835255/week @ 2024-09-29 890690/week @ 2024-10-06 868925/week @ 2024-10-13 907011/week @ 2024-10-20 883515/week @ 2024-10-27 930897/week @ 2024-11-03 887423/week @ 2024-11-10 889496/week @ 2024-11-17 791114/week @ 2024-11-24 873893/week @ 2024-12-01 982122/week @ 2024-12-08 901720/week @ 2024-12-15 403833/week @ 2024-12-22 588354/week @ 2024-12-29 943168/week @ 2025-01-05

2,898,420 downloads per month
Used in 6,083 crates (750 directly)

MIT/Apache

117MB
2M SLoC

Rust for Windows

The windows and windows-sys crates let you call any Windows API past, present, and future using code generated on the fly directly from the metadata describing the API and right into your Rust package where you can call them as if they were just another Rust module. The Rust language projection follows in the tradition established by C++/WinRT of building language projections for Windows using standard languages and compilers, providing a natural and idiomatic way for Rust developers to call Windows APIs.

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

[dependencies.windows]
version = "0.59"
features = [
    "Data_Xml_Dom",
    "Win32_Security",
    "Win32_System_Threading",
    "Win32_UI_WindowsAndMessaging",
]

Make use of any Windows APIs as needed:

use windows::{
    core::*, Data::Xml::Dom::*, Win32::Foundation::*, Win32::System::Threading::*,
    Win32::UI::WindowsAndMessaging::*,
};

fn main() -> Result<()> {
    let doc = XmlDocument::new()?;
    doc.LoadXml(h!("<html>hello world</html>"))?;

    let root = doc.DocumentElement()?;
    assert!(root.NodeName()? == "html");
    assert!(root.InnerText()? == "hello world");

    unsafe {
        let event = CreateEventW(None, true, false, None)?;
        SetEvent(event)?;
        WaitForSingleObject(event, 0);
        CloseHandle(event)?;

        MessageBoxA(None, s!("Ansi"), s!("Caption"), MB_OK);
        MessageBoxW(None, w!("Wide"), w!("Caption"), MB_OK);
    }

    Ok(())
}

Dependencies

~0.3–9.5MB
~18K SLoC