Created
May 3, 2024 21:59
-
-
Save kennykerr/a4375597c7507182570576cf9e7b6ae5 to your computer and use it in GitHub Desktop.
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 windows::{core::*, Win32::Storage::FileSystem::*}; | |
fn search_path(filename: &str) -> Result<String> { | |
let filename = &HSTRING::from(filename); | |
let len = unsafe { SearchPathW(None, filename, None, None, None) }; | |
if len == 0 { | |
return Err(Error::from_win32()); | |
} | |
let mut buffer = vec![0; len as usize]; | |
let len = unsafe { SearchPathW(None, filename, None, Some(&mut buffer), None) }; | |
buffer.truncate(len as usize); | |
Ok(String::from_utf16(&buffer)?) | |
} | |
fn main() -> Result<()> { | |
println!("{}", search_path("midl.exe")?); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment