Skip to content

Instantly share code, notes, and snippets.

@rain2307
Created August 27, 2023 02:21
Show Gist options
  • Save rain2307/7c10617cda5bfe3b6cec7a982632dc21 to your computer and use it in GitHub Desktop.
Save rain2307/7c10617cda5bfe3b6cec7a982632dc21 to your computer and use it in GitHub Desktop.
dll.rs
[target.'cfg(windows)'.dev-dependencies]
windows = { version = "0.48.0", features = [
"Win32_System_LibraryLoader",
"Win32_Foundation",
] }
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);
}
@rain2307
Copy link
Author

windows not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment