nagisa / rust_libloading

Bindings around the platform's dynamic library loading primitives with greatly improved memory safety.
https://docs.rs/libloading
ISC License
1.22k stars 100 forks source link

The specified program cannot be found #142

Open zhuyu4839 opened 5 months ago

zhuyu4839 commented 5 months ago

The dll file is https://github.com/zhuyu4839/zlgcan-driver/blob/main/zlgcan/library/windows/x86_64/zlgcan.dll

The function named GetIProperty, ReleaseIProperty, ZCAN_GetValue, ZCAN_SetValue can't found

calledResult::unwrap()on anErrvalue: GetProcAddress { source: Os { code: 127, kind: Uncategorized, message: "找不到指定的程序。" } }

nagisa commented 5 months ago

This error comes from your OS and is not an issue with libloading specifically. Unfortunately I am not in a position to provide application support here, please use other appropriate channels to discuss use of these system APIs.

zhuyu4839 commented 5 months ago

All right. but there is no panic when using dlopen2.

nagisa commented 5 months ago

Okay, that's quite curious. However as the report is written currently I’m still unable to help or investigate by myself.

In order for me to look into this, I would need a reproducer that does not involve binary executable code downloaded off internet. I’m not currently in a position to set up a VM to test your library.


If you are up to testing some things, it would be great if you compared not with dlopen2 and other competing crates, but windows API. Can you try something like:

// use the `windows-sys` crate with the "Win32_Foundation" feature enabled
use windows_sys::Win32::System::LibraryLoader;
let handle = LibraryLoader::LoadLibraryA(b"C:\\path\\to\\zlgcan.dll\0");
assert!(handle != 0);
let symbol = LibraryLoader::GetProcAddress(handle, b"ZCAN_GetValue\0");
assert!(symbol.is_some());

this is effectively what libloading should be doing under the covers. If this fails as well, then it will be curious to see what dlopen2 is doing differently and why it works. If this does work, then it might have something to do with e.g. https://github.com/nagisa/rust_libloading/pull/125.

Which brings me to another thing to try -- is this something that started happening in a recent release? Can you check if, perhaps, libloading 0.7.4 works? It should need no changes to your reproducer.

zhuyu4839 commented 5 months ago

Ok. I'll try it later because i'm refactoring the code.