Skip to content

zeon256/dllmain-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dllmain-rs

Crates.io Crates.io Downloads Docs.rs License

A proc macro to generate dllmain

Installation

Add this to your Cargo.toml:

[dependencies]
dllmain-rs = "0.1.0"

Options

#[dllmain_rs::entry] accepts optional arguments:

  • events(process_attach, process_detach, thread_attach, thread_detach)
  • panic = "abort" | "return_false"

Defaults:

  • events(process_attach)
  • panic = "abort"

Valid entry function signatures

  • fn name()
  • fn name(reason: u32)

Rejected signatures include methods, async, const, unsafe, generic functions, variadics, non-() return types, and more than one argument.

Example usage

#[dllmain_rs::entry]
fn on_process_attach() {
    // lightweight, loader-lock-safe setup
}

#[dllmain_rs::entry(events(process_attach, process_detach), panic = "return_false")]
fn on_lifecycle(reason: u32) {
    match reason {
        1 => {
            // process attach
        }
        0 => {
            // process detach
        }
        _ => {}
    }
}

Safety notes

DllMain runs under the Windows loader lock. Keep logic minimal, avoid heavy I/O, waiting on synchronization primitives, and complex re-entrancy during load/unload. If your function panics, panic = "abort" terminates the process, while panic = "return_false" returns FALSE from DllMain.

Standalone example crates

See examples/README.md for end-to-end cdylib consumer crates:

  • examples/minimal-dll
  • examples/lifecycle-dll

License

Licensed under either of

at your option.

About

A proc macro attribute to generate dllmain

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages