dynlib

Crates.iodynlib
lib.rsdynlib
version0.1.0
sourcesrc
created_at2016-11-21 17:10:05.062062
updated_at2016-11-21 17:10:05.062062
descriptionHigh level, safe-ish binding for dll loading in Rust-MSVC
homepagehttps://github.com/valarauca/dynlib
repositoryhttps://github.com/valarauca/dynlib
max_upload_size
id7328
size4,292,989
Cody Laeder (valarauca)

documentation

https://valarauca.github.io/dynlib/dynlib/index.html

README

dynlib

Simple Bindings to the Microsoft DLL Loader for Rust MSVC

Docs

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.

Commit count: 3

cargo fmt