Debian Codegraph @

third_party/rust/windows-link/readme.md

raw
1 ## Linking for Windows
2
3 The [windows-link](https://crates.io/crates/windows-link) crate provides the `link` macro that simplifies linking. The `link` macro is much the same as the one provided by [windows-targets](https://crates.io/crates/windows-targets) but uses `raw-dylib` and thus does not require import lib files.
4
5 * [Getting started](https://kennykerr.ca/rust-getting-started/)
6 * [Samples](https://github.com/microsoft/windows-rs/tree/master/crates/samples)
7 * [Releases](https://github.com/microsoft/windows-rs/releases)
8
9 Start by adding the following to your Cargo.toml file:
10
11 ```toml
12 [dependencies.windows-link]
13 version = "0.1"
14 ```
15
16 Use the `link` macro to define the external functions you wish to call:
17
18 ```rust
19 windows_link::link!("kernel32.dll" "system" fn SetLastError(code: u32));
20 windows_link::link!("kernel32.dll" "system" fn GetLastError() -> u32);
21
22 unsafe {
23 SetLastError(1234);
24 assert_eq!(GetLastError(), 1234);
25 }
26 ```