windows-link (0.100.0+paring.1)

Published 2026-10-14 03:21:29 +09:00 by paring

Installation

[registries.forgejo]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add windows-link@0.100.0+paring.1 --registry forgejo

About this package

Linking for Windows

The windows-link crate provides the link macro that simplifies linking. The link macro uses raw-dylib and thus does not require import lib files.

Start by adding the following to your Cargo.toml file:

[dependencies.windows-link]
version = "0.100"

Use the link macro to import functions and their matching function-pointer types. Here the loader functions are linked normally while MessageBoxA is resolved at runtime:

use std::ffi::c_void;
use windows_link::link;

link!("kernel32.dll" "system" fn LoadLibraryA(name: *const u8) -> *mut c_void);
link!("kernel32.dll" "system" fn GetProcAddress(
    library: *mut c_void,
    name: *const u8,
) -> *mut c_void);
link!("user32.dll" "system" fn MessageBoxA(
    hwnd: *mut c_void,
    text: *const u8,
    caption: *const u8,
    kind: u32,
) -> i32);

unsafe {
    let module = LoadLibraryA(b"user32.dll\0".as_ptr());
    let address = GetProcAddress(module, b"MessageBoxA\0".as_ptr());

    if !address.is_null() {
        let message_box: MessageBoxA = std::mem::transmute(address);

        message_box(
            std::ptr::null_mut(),
            b"text\0".as_ptr(),
            b"caption\0".as_ptr(),
            0,
        );
    }
}
Details
Cargo
2026-10-14 03:21:29 +09:00
20
2026-11-10 00:22:51 +09:00
MIT OR Apache-2.0
6.6 KiB
Assets (1)
Versions (1) View all
0.100.0+paring.1 2026-10-14