https://github.com/microsoft/windows-rs/#rust-for-windows Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Project management - + Integrations - + GitHub Sponsors - + Customer stories - + Security - * Team * Enterprise * Explore + Explore GitHub - Learn & contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Nonprofit - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} microsoft / windows-rs * Watch 83 * Star 2.8k * Fork 74 Rust for Windows MIT License 2.8k stars 74 forks Star Watch * Code * Issues 34 * Pull requests 0 * Actions * Security * Insights More * Code * Issues * Pull requests * Actions * Security * Insights master 3 branches 1 tag Go to file Code Clone HTTPS GitHub CLI [https://github.com/m] Use Git or checkout with SVN using the web URL. [gh repo clone micros] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio If nothing happens, download the GitHub extension for Visual Studio and try again. Go back Latest commit Kenny Kerr Kenny Kerr readme ... 256538e Jan 21, 2021 readme 256538e Git stats * 280 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Direct dependency management and removal of "cargo winrt" tool (#370) Dec 1, 2020 .windows win32 Jan 20, 2021 crates Publish 0.2.1 (#418) Jan 20, 2021 examples/simple Publish 0.2.1 (#418) Jan 20, 2021 src Additional type system support (#416) Jan 20, 2021 .gitattributes Direct dependency management and removal of "cargo winrt" tool (#370) Dec 1, 2020 .gitignore Initial WinRT support (#1) Dec 4, 2019 Cargo.toml Publish 0.2.1 (#418) Jan 20, 2021 build.rs Less cryptic crate names (#404) Jan 15, 2021 code_of_conduct.md Simpler and faster (#333) Oct 9, 2020 contributing.md Less cryptic crate names (#404) Jan 15, 2021 license Simpler and faster (#333) Oct 9, 2020 readme.md readme Jan 21, 2021 security.md Simpler and faster (#333) Oct 9, 2020 View code readme.md crates.io docs.rs Build and Test Rust for Windows The windows crate lets 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. Getting started Start by adding the following to your Cargo.toml file: [dependencies] windows = "0.2.1" [build-dependencies] windows = "0.2.1" This will allow Cargo to download, build, and cache Windows support as a package. Next, specify which types you need inside of a build.rs build script and the windows crate will generate the necessary bindings: fn main() { windows::build!( windows::data::xml::dom::* windows::win32::system_services::{CreateEventW, SetEvent, WaitForSingleObject} windows::win32::windows_programming::CloseHandle ); } Finally, make use of any Windows APIs as needed. mod bindings { ::windows::include_bindings!(); } use bindings::{ windows::data::xml::dom::*, windows::win32::system_services::{CreateEventW, SetEvent, WaitForSingleObject}, windows::win32::windows_programming::CloseHandle, }; fn main() -> windows::Result<()> { let doc = XmlDocument::new()?; doc.load_xml("hello world")?; let root = doc.document_element()?; assert!(root.node_name()? == "html"); assert!(root.inner_text()? == "hello world"); unsafe { let event = CreateEventW( std::ptr::null_mut(), true.into(), false.into(), std::ptr::null(), ); SetEvent(event).ok()?; WaitForSingleObject(event, 0); CloseHandle(event).ok()?; } Ok(()) } To reduce build time, use a bindings crate rather simply a module. This will allow Cargo to cache the results and build your project far more quickly. There is an experimental documentation generator for the Windows API. The documentation is published here. This can be useful to figure out how the various Windows APIs map to Rust modules and which use paths you need to use from within the build macro. For a more complete example, take a look at Robert Mikhayelyan's Minesweeper. More simple examples can be found here. About Rust for Windows Topics windows rust Resources Readme License MIT License Contributors 18 * @kennykerr * @rylev * @zachlute * @microsoftopensource * @robmikh * @GuillaumeGomez * @Alovchin91 * @arturdryomov * @Josh015 * @msftgits * @Perlmint + 7 contributors Languages * Rust 100.0% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Help * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.