• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H03-May-2022-180,025176,117

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D26-Jun-202074 65

Cargo.tomlH A D26-Jun-20207 KiB435432

Cargo.toml.orig-cargoH A D26-Jun-20206.5 KiB432428

LICENSE-APACHEH A D18-Dec-201711.1 KiB202169

LICENSE-MITH A D19-Mar-20201 KiB2016

README.mdH A D05-Jun-20204.7 KiB9165

build.rsH A D25-Jun-202034.2 KiB528513

README.md

1# winapi-rs
2[![Build status](https://github.com/retep998/winapi-rs/workflows/Rust/badge.svg)](https://github.com/retep998/winapi-rs/actions)
3[![Build status](https://ci.appveyor.com/api/projects/status/i47oonf5e7qm5utq/branch/0.3?svg=true)](https://ci.appveyor.com/project/retep998/winapi-rs/branch/0.3)
4[![Build Status](https://travis-ci.org/retep998/winapi-rs.svg?branch=0.3)](https://travis-ci.org/retep998/winapi-rs)
5[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/retep998/winapi-rs)
6[![Crates.io](https://img.shields.io/crates/v/winapi.svg)](https://crates.io/crates/winapi)
7![Lines of Code](https://tokei.rs/b1/github/retep998/winapi-rs)
8![100% unsafe](https://img.shields.io/badge/unsafe-100%25-blue.svg)
9[![Open issues](https://img.shields.io/github/issues-raw/retep998/winapi-rs.svg)](https://github.com/retep998/winapi-rs/issues)
10[![License](https://img.shields.io/crates/l/winapi.svg)](https://github.com/retep998/winapi-rs)
11
12
13[Documentation](https://docs.rs/winapi/)
14
15Official communication channel: #windows-dev on the [Rust Community Discord](https://discord.gg/aVESxV8)
16
17This crate provides raw FFI bindings to all of Windows API. They are gathered by hand using the Windows 10 SDK from Microsoft. I aim to replace all existing Windows FFI in other crates with this crate through the "[Embrace, extend, and extinguish](https://en.wikipedia.org/wiki/Embrace,_extend,_and_extinguish)" technique.
18
19If this crate is missing something you need, feel free to create an issue, open a pull request, or contact me via [other means](https://www.rustaceans.org/retep998).
20
21This crate depends on Rust 1.6 or newer on Windows. On other platforms this crate is a no-op and should compile with Rust 1.2 or newer.
22
23## Frequently asked questions ##
24
25### How do I create an instance of a union?
26
27Use `std::mem::zeroed()` to create an instance of the union, and then assign the value you want using one of the variant methods.
28
29### Why am I getting errors about unresolved imports?
30
31Each module is gated on a feature flag, so you must enable the appropriate feature to gain access to those items. For example, if you want to use something from `winapi::um::winuser` you must enable the `winuser` feature.
32
33### How do I know which module an item is defined in?
34
35You can use the search functionality in the [documentation](https://docs.rs/winapi/) to find where items are defined.
36
37### Why is there no documentation on how to use anything?
38
39This crate is nothing more than raw bindings to Windows API. If you wish to know how to use the various functionality in Windows API, you can look up the various items on [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/aa906039) which is full of detailed documentation.
40
41### Can I use this library in `no_std` projects?
42
43Yes, absolutely! By default the `std` feature of `winapi` is disabled, allowing you to write Windows applications using nothing but `core` and `winapi`.
44
45### Why is `winapi`'s `HANDLE` incompatible with `std`'s `HANDLE`?
46
47Because `winapi` does not depend on `std` by default, it has to define `c_void` itself instead of using `std::os::raw::c_void`. However, if you enable the `std` feature of `winapi` then it will re-export `c_void` from `std` and cause `winapi`'s `HANDLE` to be the same type as `std`'s `HANDLE`.
48
49### Should I still use those `-sys` crates such as `kernel32-sys`?
50
51No. Those crates are a legacy of how `winapi` 0.2 was organized. Starting with `winapi` 0.3 all definitions are directly in `winapi` itself, and so there is no longer any need to use those `-sys` crates.
52
53## Example ##
54
55Cargo.toml:
56```toml
57[target.'cfg(windows)'.dependencies]
58winapi = { version = "0.3", features = ["winuser"] }
59```
60main.rs:
61```Rust
62#[cfg(windows)] extern crate winapi;
63use std::io::Error;
64
65#[cfg(windows)]
66fn print_message(msg: &str) -> Result<i32, Error> {
67    use std::ffi::OsStr;
68    use std::iter::once;
69    use std::os::windows::ffi::OsStrExt;
70    use std::ptr::null_mut;
71    use winapi::um::winuser::{MB_OK, MessageBoxW};
72    let wide: Vec<u16> = OsStr::new(msg).encode_wide().chain(once(0)).collect();
73    let ret = unsafe {
74        MessageBoxW(null_mut(), wide.as_ptr(), wide.as_ptr(), MB_OK)
75    };
76    if ret == 0 { Err(Error::last_os_error()) }
77    else { Ok(ret) }
78}
79#[cfg(not(windows))]
80fn print_message(msg: &str) -> Result<(), Error> {
81    println!("{}", msg);
82    Ok(())
83}
84fn main() {
85    print_message("Hello, world!").unwrap();
86}
87```
88
89## Financial Support
90Do you use `winapi` in your projects? If so, you may be interested in financially supporting me on [Patreon](https://www.patreon.com/retep998). Companies in particular are especially encouraged to donate (I'm looking at you [Microsoft](https://github.com/Azure/iotedge/tree/master/edgelet)).
91