I tried to get a basic proof of concept before and after using cmake and rust here https://github.com/shadowmint/rust-dl-example , but to no avail.
The basic idea is to create a DLL and then load the following symbols:
let dl = DynamicLibrary::open(Some(dl_path));
match dl {
Ok(dll) => {
unsafe{
rtn.foo = match dll.symbol::<c_void>("foo") {
Ok(symbol) => Some(transmute(symbol)),
Err(_) => None
};
rtn.bar = match dll.symbol::<c_void>("bar") {
Ok(symbol) => Some(transmute(symbol)),
Err(_) => None
};
trace!("Read: {}", dll.symbol::<c_void>("foo"));
trace!("Read: {}", dll.symbol::<c_void>("bar"));
rtn.lib = Some(dll);
}
}
Which works in linux and osx style, but sadly fails in windows:
Compiling dltest v0.1.0 (file:///C:/projects/rust-all/rust-dl-example)
Running target\dltest-3ed01b3dac66913e.exe
running 1 test
Pattern: Some(C:\projects\rust-all\rust-dl-example\build\*foo*.dll)
Some(C:\projects\rust-all\rust-dl-example\build\libfoo.dll)
Read: Err(Error code 127)
Read: Err(Error code 127)
Successfully loaded table
Done1
Done2
stack backtrace:
1: 0x5452c8 - main
2: 0x549525 - main
3: 0x54effd - main
4: 0x54ecc2 - main
5: 0x4d8e8d - main
6: 0x402411
7: 0x4023e3
8: 0x40238d
9: 0x40ccbc
10: 0x43d438 - main
11: 0x52e277 - main
12: 0x54d4cc - main
13: 0x54fc0f - main
14: 0x54fbe9 - main
15: 0x54d55e - main
16: 0x54d309 - main
17: 0x54d116 - main
18: 0x54e64d - main
19: 0x76fc652d - BaseThreadInitThunk
task failed during unwinding. aborting.
Error code 127 is the magic of windows for "no symbol found", but first of all it does not return correctly as an error, and secondly, I see nothing wrong with my DLL. It works fine with the c ... program and it has no strange connections:

What's happening? Has anyone got a working example of a DLL with windows and rust?