Created
February 9, 2024 18:15
-
-
Save kennykerr/5c953c88d59257c6cbaeeb5cd5fb3f0d to your computer and use it in GitHub Desktop.
This file contains 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
[dependencies.windows] | |
version = "0.52" | |
features = [ | |
"Win32_Foundation", | |
"Win32_System_LibraryLoader", | |
] |
This file contains 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::Foundation::*, Win32::System::LibraryLoader::*}; | |
pub unsafe fn delay_load<T>(library: PCSTR, function: PCSTR) -> Option<T> { | |
let library = LoadLibraryExA(library, None, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); | |
let Ok(library) = library else { | |
return None; | |
}; | |
let address = GetProcAddress(library, function); | |
if address.is_some() { | |
return Some(std::mem::transmute_copy(&address)); | |
} | |
_ = FreeLibrary(library); | |
None | |
} | |
fn main() { | |
unsafe { | |
if let Some(api) = delay_load::<ShellMessageBoxW>(s!("shlwapi.dll"), s!("ShellMessageBoxW")) | |
{ | |
api(0, 0, w!("text"), w!("title"), 16384); | |
} else { | |
println!("Can't find API"); | |
} | |
} | |
} | |
type ShellMessageBoxW = unsafe extern "cdecl" fn( | |
happinst: usize, | |
hwnd: usize, | |
lpctext: PCWSTR, | |
lpctitle: PCWSTR, | |
fustyle: u32, | |
... | |
) -> i32; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment