Rust for Windows
Build and Test

Rust for Windows

The windows crate potential that you can call any Windows API previous, point out, and future the usage of code generated on the soar straight a long way from the metadata describing the API and honest into your Rust kit the save chances are high you’ll presumably additionally call them as if they had been honest one other Rust module.

The Rust language projection follows in the custom established by C++/WinRT of making language projections for Windows the usage of long-established languages and compilers, providing a natural and idiomatic arrangement for Rust developers to call Windows APIs.

Getting started

Initiate by adding the next to your Cargo.toml file:



This can enable Cargo to earn, compose, and cache Windows give a prefer to as a kit. Next, specify which kinds you wish interior of a compose script and the windows crate will generate the well-known bindings:

fn predominant() {
    windows:: compose!(
        windows:: information:: xml:: dom:: *
        windows:: safe32:: system_services:: {CreateEventW, SetEvent, WaitForSingleObject}
        windows:: safe32:: windows_programming:: CloseHandle

Sooner or later, compose consume of any Windows APIs as wanted.

mod bindings {
    :: windows:: include_bindings!();

consume bindings:: {
    windows:: information:: xml:: dom:: *,
    windows:: safe32:: system_services:: {CreateEventW, SetEvent, WaitForSingleObject},
    windows:: safe32:: windows_programming:: CloseHandle,

fn predominant() -> windows:: Result {
    let doc = XmlDocument:: current()?;
    doc.load_xml("hello world")?;

    let root = doc.document_element()?;
    disclose!(root.node_name()? == "html");
    disclose!(root.inner_text()? == "hello world");

    unsafe {
        let tournament = CreateEventW(
            std:: ptr:: null_mut(),
            std:: ptr:: null(),

        WaitForSingleObject(tournament, 0);


To lower compose time, consume a bindings crate reasonably merely a module. This can enable Cargo to cache the outcomes and compose your project a long way extra hasty.

There is an experimental documentation generator for the Windows API. The documentation is printed right here. This is in a position to additionally be agreeable to work out how the diversified Windows APIs scheme to Rust modules and which consume paths it is advisable to make consume of from at some stage in the compose macro.

For a extra total instance, earn a note at Robert Mikhayelyan’s Minesweeper. More straightforward examples could possibly additionally additionally be chanced on right here.

Read More

Recent Content