All Projects → retep998 → Winapi Rs

retep998 / Winapi Rs

Licence: other
Rust bindings to Windows API

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Winapi Rs

Chineseutil
PHP 中文工具包,支持汉字转拼音、拼音分词、简繁互转、数字、金额大写;QQ群:17916227
Stars: ✭ 413 (-66.61%)
Mutual labels:  ffi
Winapi
A simple, direct, ultra-thin CLR library for high-performance Win32 Native Interop
Stars: ✭ 636 (-48.59%)
Mutual labels:  winapi
Rucaja
Calling the JVM from Rust via JNI
Stars: ✭ 35 (-97.17%)
Mutual labels:  ffi
Rust Cpp
Embed C++ directly inside your rust code!
Stars: ✭ 502 (-59.42%)
Mutual labels:  ffi
Core
MetaCall: The ultimate polyglot programming experience.
Stars: ✭ 596 (-51.82%)
Mutual labels:  ffi
Php Ffi Examples
Runnable examples to learn how PHP FFI works
Stars: ✭ 26 (-97.9%)
Mutual labels:  ffi
Ffi Overhead
comparing the c ffi (foreign function interface) overhead on various programming languages
Stars: ✭ 387 (-68.71%)
Mutual labels:  ffi
Fruity
Rusty bindings for Apple libraries
Stars: ✭ 72 (-94.18%)
Mutual labels:  ffi
Cxx.jl
The Julia C++ Interface
Stars: ✭ 620 (-49.88%)
Mutual labels:  ffi
Rust V8worker2
Minimal Rust binding to V8 (based on ry/libv8worker2)
Stars: ✭ 33 (-97.33%)
Mutual labels:  ffi
Go Cshared Examples
Calling Go Functions from Other Languages using C Shared Libraries
Stars: ✭ 541 (-56.27%)
Mutual labels:  ffi
Dart native
Write iOS&Android Code using Dart. This package liberates you from redundant glue code and low performance of Flutter Channel.
Stars: ✭ 564 (-54.41%)
Mutual labels:  ffi
Hcwiid
Haskell binding for CWiid (wiimote)
Stars: ✭ 7 (-99.43%)
Mutual labels:  ffi
Haskellr
The full power of R in Haskell.
Stars: ✭ 491 (-60.31%)
Mutual labels:  ffi
Dustr
Dart - rust - Flutter compatibility
Stars: ✭ 37 (-97.01%)
Mutual labels:  ffi
Pyo3
Rust bindings for the Python interpreter
Stars: ✭ 5,110 (+313.1%)
Mutual labels:  ffi
Rust Python Example
Example of using Rust to Extend Python
Stars: ✭ 699 (-43.49%)
Mutual labels:  ffi
Ffi Platypus
Write Perl bindings to non-Perl libraries with FFI. No XS required.
Stars: ✭ 80 (-93.53%)
Mutual labels:  ffi
Qtdirect3d
QDirect3DWidget implementation similar to the built-in QOpenGLWidget
Stars: ✭ 60 (-95.15%)
Mutual labels:  winapi
Zion
A statically-typed strictly-evaluated garbage-collected readable programming language.
Stars: ✭ 33 (-97.33%)
Mutual labels:  ffi

winapi-rs

Build status Build status Build Status Gitter Crates.io Lines of Code 100% unsafe Open issues License

Documentation

Official communication channel: #windows-dev on the Rust 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 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.

Frequently asked questions

How do I create an instance of a union?

Use std::mem::zeroed() to create an instance of the union, and then assign the value you want using one of the variant methods.

Why am I getting errors about unresolved imports?

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.

How do I know which module an item is defined in?

You can use the search functionality in the documentation to find where items are defined.

Why is there no documentation on how to use anything?

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 which is full of detailed documentation.

Can I use this library in no_std projects?

Yes, absolutely! By default the std feature of winapi is disabled, allowing you to write Windows applications using nothing but core and winapi.

Why is winapi's HANDLE incompatible with std's HANDLE?

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.

Should I still use those -sys crates such as kernel32-sys?

No. 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.

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();
}

Financial Support

Do you use winapi in your projects? If so, you may be interested in financially supporting me on Patreon. Companies in particular are especially encouraged to donate (I'm looking at you Microsoft).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].