https://github.com/qixinynan/libloader
A easy-to-use dll loader for rust that based on libloading
https://github.com/qixinynan/libloader
rust
Last synced: 4 months ago
JSON representation
A easy-to-use dll loader for rust that based on libloading
- Host: GitHub
- URL: https://github.com/qixinynan/libloader
- Owner: qixinynan
- License: mit
- Created: 2022-09-12T09:06:08.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-12T13:23:09.000Z (almost 4 years ago)
- Last Synced: 2026-01-13T20:57:44.564Z (6 months ago)
- Topics: rust
- Language: Rust
- Homepage: https://crates.io/crates/libloader
- Size: 2.85 MB
- Stars: 27
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Welcome to libloader 👋
> libloader is a easy-to-use DLL loader for rust that based on libloading
It is very easy to dynamically call a function from dynamic link library (DLL files for Windows, so files for Unix/Linux dylib for macOS )
Use this function to get the function from DLL
```rust
get_libfn!(
"path.dll",
"func_name",
name_to_call,
return_type, // ifreturn type is none, use "()" instead
param1_name: param1_type
param2_name: param2_type
param3_name: param3_type
...
);
```
For example, We have these functions from libstd.dylib
```rust
// lib.rs (compiled into libstd.dylib)
#[no_mangle]
pub fn println(str: &str) {
println!("{}", str);
}
#[no_mangle]
pub fn add(a: usize, b: usize) -> usize {
a + b
}
#[no_mangle]
pub fn print_hello() {
println!("Hello");
}
```
We can call it with:
```rust
// main.rs
use libloader::libloading
fn main() {
get_libfn!("libstd.dylib", "println", my_println, (), str: &str);
my_println("Hello World");
get_libfn!("libstd.dylib", "add", my_add, usize, a: usize, b: usize);
println!("10 + 20 = {}", my_add(10, 20));
get_libfn!("libstd.dylib", "print_hello", my_print_hello, ());
my_print_hello();
}
```
The output is:
```
Hello World
10 + 20 = 30
hello
```