Why doesn't default-target on docs.rs work yet?
2 files changed
tree: 90425eaaf2b66d03855941be7f5ba6d9a4ce226c
  1. i686/
  2. src/
  3. tests/
  4. x86_64/
  5. .gitattributes
  6. .gitignore
  7. .travis.yml
  8. appveyor.yml
  9. build.rs
  10. Cargo.toml
  11. CONTRIBUTING.md
  12. LICENSE-APACHE
  13. LICENSE-MIT
  14. RabbitCode.md
  15. README.md
README.md

winapi-rs Build status Build Status Gitter Crates.io Lines of Code 100% unsafe

Documentation

Official IRC channel: #winapi on Mozilla IRC

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” technique.

If this crate is missing something you need, feel free to create an issue, open a pull request, or contact me via other means.

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.

Example

Cargo.toml:

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winuser"] }

main.rs:

#[cfg(windows)] extern crate winapi;
use std::io::Error;

#[cfg(windows)]
fn print_message(msg: &str) -> Result<i32, Error> {
    use std::ffi::OsStr;
    use std::iter::once;
    use std::os::windows::ffi::OsStrExt;
    use std::ptr::null_mut;
    use winapi::um::winuser::{MB_OK, MessageBoxW};
    let wide: Vec<u16> = OsStr::new(msg).encode_wide().chain(once(0)).collect();
    let ret = unsafe {
        MessageBoxW(null_mut(), wide.as_ptr(), wide.as_ptr(), MB_OK)
    };
    if ret == 0 { Err(Error::last_os_error()) }
    else { Ok(ret) }
}
#[cfg(not(windows))]
fn print_message(msg: &str) -> Result<(), Error> {
    println!("{}", msg);
    Ok(())
}
fn main() {
    print_message("Hello, world!").unwrap();
}