Rust系统编程之Windows API

调用Windows API

1.Rust Windows官方文档

windows - Rust (microsoft.github.io)

2.使用Windows API的例子

[Cargo.toml]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[package]
name = "windowsapi"
version = "0.1.0"
edition = "2021"

[dependencies.windows]
version = "0.43.0"
features = [
"Win32_Foundation",
"Win32_UI_WindowsAndMessaging",
"Win32_Storage_FileSystem",
"Win32_Foundation",
"Win32_Security"
]

[src/main.rs]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use windows::{
core::*,
Win32::Storage::FileSystem::*,
};

fn main() {
unsafe {
let new_fil = CreateFileA(s!("C:\\Users\\Jnz\\Desktop\\test.txt"),
FILE_GENERIC_WRITE,
FILE_SHARE_WRITE,
None,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL , None);
match new_fil {
Ok(v) => println!("Create success with handle: {}", v.0),
Err(e) => println!("Create file failed. {e:?}"),
}
}
}

Rust系统编程之Windows API
http://helloymf.github.io/2023/04/10/rust-xi-tong-bian-cheng-zhi-windows-api/
作者
JNZ
许可协议