生成 DLL 转发的函数。
```rust use forward_dll::ForwardModule;
pub struct VersionModule;
const VERSION_LIB: VersionModule = VersionModule;
pub extern "system" fn DllMain(inst: isize, reason: u32, _: *const u8) -> u32 { if reason == 1 { println!("==> version.dll loaded"); VERSIONLIB.init().unwrap(); println!("==> version.dll initialized"); } 1 } ```
注意,#[forward(target = "path/of/your/dll")]
中的路径,应在编译期可以访问到(过程宏会读取这个文件并提取出导出表),如果这个路径为相对路径,则应相对于 Cargo.toml
所在的目录。
```rust forwarddll::forwarddll!( "C:\Windows\system32\version.dll", DLLVERSIONFORWARDER, GetFileVersionInfoA GetFileVersionInfoByHandle GetFileVersionInfoExA GetFileVersionInfoExW GetFileVersionInfoSizeA GetFileVersionInfoSizeExA GetFileVersionInfoSizeExW GetFileVersionInfoSizeW GetFileVersionInfoW VerFindFileA VerFindFileW VerInstallFileA VerInstallFileW VerLanguageNameA VerLanguageNameW VerQueryValueA VerQueryValueW );
pub extern "system" fn DllMain(inst: isize, reason: u32, _: *const u8) -> u32 { if reason == 1 { // 这里要自行持有底层的 version.dll 的句柄,防止被释放。 let _ = forwarddll::utils::loadlibrary("C:\Windows\system32\version.dll"); // 调用 forwardall 方法,建立导出函数与目标函数之间的映射关系。 let _ = unsafe { DLLVERSIONFORWARDER.forward_all() }; } 1 } ```
powershell
cargo build -p version; cargo run -p just-call-version
Copyright (c) 2022-present, hamflx