windows-rs README

The project's README from github.com/microsoft/windows-rs. As one markdown file: README.md.

windows-rs provides Rust crates for Windows APIs, from COM support and system services to UI and raw bindings.

Prefer the focused crates below when they cover the functionality you need. For additional APIs, windows-bindgen can generate a minimal project-specific binding, while windows and windows-sys provide broad API coverage behind feature flags for binary applications.

Reusable libraries should avoid the windows and windows-sys umbrella crates. They add dependency weight and version churn, and several libraries can bring incompatible versions of the same large crate into one dependency tree. Prefer the focused crates for shared Windows types and generate any remaining private bindings with windows-bindgen.

Each crate page covers usage and maintenance. Generated API documentation is available on docs.rs.

Crates

Core types and interop

Crate Description
windows-core COM and WinRT types, traits, and authoring macros.
windows-result Windows error handling and propagation.
windows-strings Windows string types, conversions, and macros.
windows-link Links C-style functions without import libraries.

Values and collections

Crate Description
windows-collections WinRT collections.
windows-numerics Graphics vectors and matrices.
windows-reference Implementation of WinRT IReference<T>.
windows-time WinRT DateTime and TimeSpan types.

Async and threading

Crate Description
windows-future WinRT asynchronous operations as Rust futures.
windows-threading Safe wrapper over the Win32 thread pool.

System services

Crate Description
windows-registry Safe Windows registry access.
windows-services Support for authoring Windows services.
windows-version Queries the Windows version at runtime.

UI and graphics

Crate Description
windows-reactor Declarative UI library backed by WinUI 3.
windows-canvas 2D graphics built on Direct2D.
windows-composition Windows composition visuals.
windows-webview Safe wrapper around the WebView2 browser control.
windows-window Window creation and message dispatch.
windows-pickers Windows file and folder pickers.
windows-animation Wrapper around the Windows Animation Manager.
windows-reactor-setup Stages the Windows App Runtime.

Code generation and metadata

Crate Description
windows-clang Generates RDL from C and C++ headers using libclang.
windows-default Embedded Windows metadata for build tools.
windows-metadata Reads and writes ECMA-335 metadata.
windows-rdl Parses RDL and generates ECMA-335 metadata.
cppwinrt Packages the C++/WinRT compiler.

Macro implementation

These crates implement macros exported by windows-core. Applications should use the windows-core exports rather than depend on them directly.

Crate Description
windows-implement Implements the #[implement] macro.
windows-interface Implements the #[interface] macro.

Windows API bindings

Use windows-bindgen when the focused crates above do not cover the APIs you need. Binary applications may instead prefer the convenience of the pre-generated windows or windows-sys umbrella crate.

Crate Description
windows-bindgen Generates Rust bindings from Windows metadata.
windows Typed bindings for C-style, COM, and WinRT APIs.
windows-sys Raw bindings for C-style Windows APIs.

windows-rs (microsoft/windows-rs)

Searching Database…

这是什么?windows-rs 是微软官方提供的一组 Rust crate,用于封装 Windows API,涵盖从 COM 和 WinRT 支持到系统服务和界面等内容,让 Rust 程序能够调用 Windows 平台的功能。
这是一个库,还是一整套 crate?它是由许多专注单一功能的 crate 组成的工作区(如 windows-core、windows-registry、windows-webview 等),另外还有两个综合 crate:windows 和 windows-sys,它们通过功能开关(feature flag)打包了较广的 API 覆盖范围。
我该如何把它添加到项目中?将你需要的具体小型 crate 添加为 Cargo 依赖即可;如果是二进制应用,也可以使用综合 crate windows 或 windows-sys。每个 crate 的生成版 API 文档都可以在 docs.rs 上查看。
如果缺少某些 API 的绑定,我需要自己生成吗?是的。如果小型 crate 没有涵盖你需要的 API,可以使用 windows-bindgen,根据 Windows 元数据生成针对特定项目的精简绑定。
为什么库不应该直接依赖 windows 或 windows-sys 这两个 crate?可复用的库应避免依赖综合 crate,因为它们会增加依赖的体积和版本变动频率;不同的库如果引入同一大型 crate 的不兼容版本,就可能在同一个依赖树中产生冲突。
哪些人应该使用小型 crate,哪些人应该使用综合 crate?库的作者应优先使用小型 crate 来处理共享的 Windows 类型,并按需生成私有绑定;二进制应用则可以借助综合 crate windows 或 windows-sys 的便利性。
这个只能在 Windows 上使用吗?是的。这些 crate 封装的是原生 Windows API(COM、WinRT、Win32),因此专门面向 Windows 平台。
windows-reactor 是什么?它是一个基于 WinUI 3 的声明式界面库,属于界面与图形 crate 组的一部分。
我能用它构建原生界面应用吗?可以。windows-reactor、windows-canvas、windows-composition、windows-webview 和 windows-window 等 crate 分别提供声明式界面、基于 Direct2D 的二维图形、组合视觉效果、嵌入式 WebView2 浏览器控件,以及窗口创建和消息分发功能。
能否直接调用 C/C++ 头文件?可以。windows-clang 借助 libclang 从 C 和 C++ 头文件生成 RDL 元数据,之后即可据此生成绑定。
What are similar projects?FreeRDP, iced, openai-python, RxJS, roslyn, pdfcraft, xi-editor, glfw
Creator
microsoft
Size
1.3 GB
Stars
12.8K
Age
7y
Commits · 90 Days