tree: ca2d55a57156e2104e53acec7070ed75f805828e [path history] [tgz]
  1. src/
  2. .android-checksum.json
  3. .cargo-checksum.json
  4. Android.bp
  5. Cargo.lock
  6. Cargo.toml
  7. cargo_embargo.json
  8. cargo_embargo_target_windows_enabled.bp.fragment
  9. license-apache-2.0
  10. METADATA
  11. MODULE_LICENSE_APACHE2
  12. readme.md
crates/windows-link/readme.md

Linking for Windows

The windows-link crate provides the link macro that simplifies linking. The link macro is much the same as the one provided by windows-targets but 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.1"

Use the link macro to define the external functions you wish to call:

windows_link::link!("kernel32.dll" "system" fn SetLastError(code: u32));
windows_link::link!("kernel32.dll" "system" fn GetLastError() -> u32);

unsafe {
    SetLastError(1234);
    assert_eq!(GetLastError(), 1234);
}