Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork393
Rust bindings to Windows API
License
Apache-2.0, MIT licenses found
Licenses found
retep998/winapi-rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Official communication channel: #windows-dev on theRust Community Discord
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 viaother 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.
Usestd::mem::zeroed()
to create an instance of the union, and then assign the value you want using one of the variant methods.
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 fromwinapi::um::winuser
you must enable thewinuser
feature.
You can use the search functionality in thedocumentation to find where items are defined.
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 onMSDN which is full of detailed documentation.
Yes, absolutely! By default thestd
feature ofwinapi
is disabled, allowing you to write Windows applications using nothing butcore
andwinapi
.
Becausewinapi
does not depend onstd
by default, it has to definec_void
itself instead of usingstd::os::raw::c_void
. However, if you enable thestd
feature ofwinapi
then it will re-exportc_void
fromstd
and causewinapi
'sHANDLE
to be the same type asstd
'sHANDLE
.
No. Those crates are a legacy of howwinapi
0.2 was organized. Starting withwinapi
0.3 all definitions are directly inwinapi
itself, and so there is no longer any need to use those-sys
crates.
Cargo.toml:
[target.'cfg(windows)'.dependencies]winapi = {version ="0.3",features = ["winuser"] }
main.rs:
#[cfg(windows)]externcrate winapi;use std::io::Error;#[cfg(windows)]fnprint_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))]fnprint_message(msg:&str) ->Result<(),Error>{println!("{}", msg);Ok(())}fnmain(){print_message("Hello, world!").unwrap();}
Do you usewinapi
in your projects? If so, you may be interested in financially supporting me onPatreon. Companies in particular are especially encouraged to donate (I'm looking at youMicrosoft).
About
Rust bindings to Windows API
Topics
Resources
License
Apache-2.0, MIT licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.