-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error 126 while loadind DLL compiled by Rust on Windows #33842
Comments
Could you also provide details about how you're linking the DLL into an executable and running it? |
I've created simple C++ program to test this case:
Also I've tried to load it into Lua script:
However the error is laconic: "loop or previous error loading module 'test'". |
In C++ it looks like that may be an error as "test.dll" can't be cast to a wide string (LPCWSTR), right? That'd cause it to be decoded as utf-16 which may explain the unusual characters? In Lua I'm not really sure what the error would be though |
Yeah, it should be |
Dependency Walker will always complain about those API dlls, but they're perfectly fine. Don't mind them, it's just how newer versions of Windows handle system APIs and Dependency Walker doesn't understand them. Anyway, I just tested creating a Rust DLL and was able to both link against it at link time, as well as dynamically load it using LoadLibrary using a simple C++ program. So apparently "test.dll", if reinterpreted as UTF-16, is in fact "整瑳搮汬", so if you just fix your Also if you update to the latest nightly you can use the new |
Yeah, shame on me: wide string must be used in C++. With it DLL loads flawlessly. Thank you! Unfortunately nightly x86 Rust doesn't compile DLL with crate
Could you give me the cue is there any information about new crate types? |
Ah no worries! The cargo support for cdylib is coming in rust-lang/cargo#2741, but otherwise it sounds like we're all good here, so I'm gonna close. |
I'm having the same issue here. This is my project which has 3 crates: one static lib, one dynamic lib (cdylib) and an executable.
I also tried to create a small C program that uses (this is the C loader:) #include <windows.h>
#include <stdio.h>
int main() {
HMODULE lib = LoadLibraryA("ecsde/target/release/ecs_game.dll");
if (lib) {
printf("Hurray!\n");
} else {
DWORD last_err = GetLastError();
printf("Failed to load. Last err = %d\n", last_err);
}
} |
Loading DLL compiled by Rust 1.8.0 on Windows 10 x64 results in error 126.
lib.rs as simple as follow:
Cargo.toml
It's built by simple
cargo build --release
rustc --version --verbose
As a result DependencyWalker shows a lot of API-MS-W1IN-CORE-* DLLs missing in my system for the compiled DLL:
API-MS-WIN-CORE-APIQUERY-L1-1-0.DLL
API-MS-WIN-CORE-APPCOMPAT-L1-1-1.DLL
API-MS-WIN-CORE-APPINIT-L1-1-0.DLL
API-MS-WIN-CORE-ATOMS-L1-1-0.DLL
...
However on my Windows 10 x64 system I've already installed MS Visual Studio 2015 and MS C++ Redistributables 2005, 2010, 2012, 2013 and 2015.
I've picked up errors during the DLL loading by ProcessMonitor. I'm confused by missing 整瑳搮汬.DLL.
How can I help to solve this problem?
The text was updated successfully, but these errors were encountered: