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

..03-May-2022-

src/H03-May-2022-136,519133,132

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

Cargo.tomlH A D01-Jan-19705.5 KiB334330

Cargo.toml.orig-cargoH A D03-Jan-20185 KiB327322

LICENSE-APACHEH A D18-Dec-201711.1 KiB202169

LICENSE-MITH A D18-Dec-20171 KiB2016

README.mdH A D02-Jan-20183.2 KiB6648

build.rsH A D28-Dec-201723.9 KiB393378

README.md

1# winapi-rs [![Build status](https://ci.appveyor.com/api/projects/status/i47oonf5e7qm5utq/branch/master?svg=true)](https://ci.appveyor.com/project/retep998/winapi-rs/branch/master) [![Build Status](https://travis-ci.org/retep998/winapi-rs.svg?branch=master)](https://travis-ci.org/retep998/winapi-rs) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/retep998/winapi-rs) [![Crates.io](https://img.shields.io/crates/v/winapi.svg)](https://crates.io/crates/winapi) ![Lines of Code](https://tokei.rs/b1/github/retep998/winapi-rs) ![100% unsafe](https://img.shields.io/badge/unsafe-100%25-blue.svg) #
2
3[Documentation](https://docs.rs/winapi/*/x86_64-pc-windows-msvc/winapi/)
4
5Official IRC channel: #winapi on [Mozilla IRC](https://wiki.mozilla.org/IRC)
6
7This 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.
8
9If 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).
10
11This 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.
12
13## Frequently asked questions ##
14
15### How do I create an instance of a union?
16
17Use `std::mem::zeroed()` to create an instance of the union, and then assign the value you want using one of the variant methods.
18
19### Why am I getting errors about unresolved imports?
20
21Each 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.
22
23### How do I know which module an item is defined in?
24
25You can use the search functionality in the [documentation](https://docs.rs/winapi/*/x86_64-pc-windows-msvc/winapi/) to find where items are defined.
26
27### Why is there no documentation on how to use anything?
28
29This 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.
30
31## Example ##
32
33Cargo.toml:
34```toml
35[target.'cfg(windows)'.dependencies]
36winapi = { version = "0.3", features = ["winuser"] }
37```
38main.rs:
39```Rust
40#[cfg(windows)] extern crate winapi;
41use std::io::Error;
42
43#[cfg(windows)]
44fn print_message(msg: &str) -> Result<i32, Error> {
45    use std::ffi::OsStr;
46    use std::iter::once;
47    use std::os::windows::ffi::OsStrExt;
48    use std::ptr::null_mut;
49    use winapi::um::winuser::{MB_OK, MessageBoxW};
50    let wide: Vec<u16> = OsStr::new(msg).encode_wide().chain(once(0)).collect();
51    let ret = unsafe {
52        MessageBoxW(null_mut(), wide.as_ptr(), wide.as_ptr(), MB_OK)
53    };
54    if ret == 0 { Err(Error::last_os_error()) }
55    else { Ok(ret) }
56}
57#[cfg(not(windows))]
58fn print_message(msg: &str) -> Result<(), Error> {
59    println!("{}", msg);
60    Ok(())
61}
62fn main() {
63    print_message("Hello, world!").unwrap();
64}
65```
66