libs/windows/windows-rs/src/Windows/mod.rs was a hand-pruned snapshot with no recipe behind it; adding a WinRT namespace meant hand-copying vtables. Now tools/windows_bindgen (standalone, windows-bindgen 0.62.1) regenerates it from filter.txt: package mode with the COM `_Impl` traits, Win32 imports linked through windows_core, upstream's 800-column rustfmt (the repo-root rustfmt.toml disables formatting and has to be overridden), the filter closed over every dependency the generator would otherwise skip a member for, the namespace tree folded into one file with every feature gate kept, and the two spots where the published 0.62.1 generator predates the vendored core 0.62.2 normalized (Error::from_thread, imp::array_proxy). The filter is the old file's item list plus Windows.Globalization.Language, Windows.Media.SpeechRecognition and Windows.Media.SpeechSynthesis for the OS speech engines. The generated `deprecated` gate is declared as a feature. Checked on x86_64-pc-windows-msvc: platform, video, network, mpterm, system-speech. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| src | ||
| Cargo.toml | ||
| license-apache-2.0 | ||
| license-mit | ||
| readme.md | ||
| rustfmt.toml | ||
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, <=0.62"
features = [
"Data_Xml_Dom",
"Win32_Security",
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
]
Using a range instead of the default Caret requirements helps avoid duplicate versions in downstream graphs and improves resolver flexibility.
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(())
}