Created
August 27, 2023 02:21
-
-
Save rain2307/7c10617cda5bfe3b6cec7a982632dc21 to your computer and use it in GitHub Desktop.
dll.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[target.'cfg(windows)'.dev-dependencies] | |
windows = { version = "0.48.0", features = [ | |
"Win32_System_LibraryLoader", | |
"Win32_Foundation", | |
] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{os::windows::ffi::OsStrExt, path::Path}; | |
use cxx_api; | |
fn load_dll(dll_path: &str) { | |
let path = std::ffi::OsStr::new(dll_path).encode_wide().chain(Some(0)).collect::<Vec<u16>>(); | |
let path = windows::core::PCWSTR(path.as_ptr() as *mut _); | |
let result = unsafe { windows::Win32::System::LibraryLoader::SetDllDirectoryW(path) }; | |
println!("cargo:warning=load result {} {:?}", dll_path, result); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
windows not working