#dll #msvc #dynamic #linker

dynlib

High level, safe-ish binding for dll loading in Rust-MSVC

1 unstable release

Uses old Rust 2015

0.1.0 Nov 21, 2016

#11 in #msvc

Apache-2.0

2MB
139 lines

Contains (static library, 1MB) src/test_dll.dll.lib, (Windows DLL, 725KB) src/test_dll.dll

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.

Dependencies