dllmain-rs
A proc macro to generate dllmain
Installation
Add this to your Cargo.toml:
[]
= "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
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-dllexamples/lifecycle-dll
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.