]> git.proxmox.com Git - rustc.git/blob - src/vendor/winapi/README.md
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / vendor / winapi / README.md
1 # winapi-rs
2 [![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)
3 [![Build Status](https://travis-ci.org/retep998/winapi-rs.svg?branch=0.3)](https://travis-ci.org/retep998/winapi-rs)
4 [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/retep998/winapi-rs)
5 [![Crates.io](https://img.shields.io/crates/v/winapi.svg)](https://crates.io/crates/winapi)
6 ![Lines of Code](https://tokei.rs/b1/github/retep998/winapi-rs)
7 ![100% unsafe](https://img.shields.io/badge/unsafe-100%25-blue.svg)
8 [![Open issues](https://img.shields.io/github/issues-raw/retep998/winapi-rs.svg)](https://github.com/retep998/winapi-rs/issues)
9 [![License](https://img.shields.io/crates/l/winapi.svg)](https://github.com/retep998/winapi-rs)
10
11
12 [Documentation](https://docs.rs/winapi/*/x86_64-pc-windows-msvc/winapi/)
13
14 Official IRC channel: #winapi on [Mozilla IRC](https://wiki.mozilla.org/IRC)
15
16 This 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](http://en.wikipedia.org/wiki/Embrace,_extend_and_extinguish)" technique.
17
18 If this crate is missing something you need, feel free to create an issue, open a pull request, or contact me via [other means](http://www.rustaceans.org/retep998).
19
20 This 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.
21
22 ## Frequently asked questions ##
23
24 ### How do I create an instance of a union?
25
26 Use `std::mem::zeroed()` to create an instance of the union, and then assign the value you want using one of the variant methods.
27
28 ### Why am I getting errors about unresolved imports?
29
30 Each 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.
31
32 ### How do I know which module an item is defined in?
33
34 You can use the search functionality in the [documentation](https://docs.rs/winapi/*/x86_64-pc-windows-msvc/winapi/) to find where items are defined.
35
36 ### Why is there no documentation on how to use anything?
37
38 This 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.
39
40 ### Can I use this library in `no_std` projects?
41
42 Yes, absolutely! By default the `std` feature of `winapi` is disabled, allowing you to write Windows applications using nothing but `core` and `winapi`.
43
44 ### Why is `winapi`'s `HANDLE` incompatible with `std`'s `HANDLE`?
45
46 Because `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`.
47
48 ## Example ##
49
50 Cargo.toml:
51 ```toml
52 [target.'cfg(windows)'.dependencies]
53 winapi = { version = "0.3", features = ["winuser"] }
54 ```
55 main.rs:
56 ```Rust
57 #[cfg(windows)] extern crate winapi;
58 use std::io::Error;
59
60 #[cfg(windows)]
61 fn print_message(msg: &str) -> Result<i32, Error> {
62 use std::ffi::OsStr;
63 use std::iter::once;
64 use std::os::windows::ffi::OsStrExt;
65 use std::ptr::null_mut;
66 use winapi::um::winuser::{MB_OK, MessageBoxW};
67 let wide: Vec<u16> = OsStr::new(msg).encode_wide().chain(once(0)).collect();
68 let ret = unsafe {
69 MessageBoxW(null_mut(), wide.as_ptr(), wide.as_ptr(), MB_OK)
70 };
71 if ret == 0 { Err(Error::last_os_error()) }
72 else { Ok(ret) }
73 }
74 #[cfg(not(windows))]
75 fn print_message(msg: &str) -> Result<(), Error> {
76 println!("{}", msg);
77 Ok(())
78 }
79 fn main() {
80 print_message("Hello, world!").unwrap();
81 }
82 ```