Crates.io | dynlib |
lib.rs | dynlib |
version | 0.1.0 |
source | src |
created_at | 2016-11-21 17:10:05.062062 |
updated_at | 2016-11-21 17:10:05.062062 |
description | High level, safe-ish binding for dll loading in Rust-MSVC |
homepage | https://github.com/valarauca/dynlib |
repository | https://github.com/valarauca/dynlib |
max_upload_size | |
id | 7328 |
size | 4,292,989 |
Simple Bindings to the Microsoft DLL Loader for Rust MSVC
To include in your project:
[dependencies]
dynlib = "0.0.1"
This crate WILL NOT WORK outside of Rust MSVC. Please note that.
This provides simple abstraction of the LoadLibraryExA
interface found
on Windows platforms. A very simple example of this crates functionality
use dynlib::{VoidPtr,LoadWinDynLib,DynLibWin};
let lib: DynLibWin = LoadWinDynLib::new()
.search_application_dir()
.load("test_dll.dll")?;
let func: VoidPtr = lib.load_function("addition")?;
let callable: extern "Rust" fn(u64,u64)->u64 = unsafe{ mem::transmute(func)};
assert_eq( callable(5u64,5u64), 10u64);
Unsafe code is required to cast the function pointer. The DynLibWin
type
will not unload it's module when it is dropped. It must be manually freed.
When you free the DynLibWin
all functions that were pulled from it will
be invalidated, and freed from memory. So calling them will results in
a memory segmentation fault, and likely your application crashing.
I just feel it is a safer alternative to have DLL's live for your entire application's life. The loaded DLL's memory is shared between processes, so there isn't a save ram argument here.