Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Created May 3, 2024 21:59
Show Gist options
  • Save kennykerr/a4375597c7507182570576cf9e7b6ae5 to your computer and use it in GitHub Desktop.
Save kennykerr/a4375597c7507182570576cf9e7b6ae5 to your computer and use it in GitHub Desktop.
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