1use super::*;
2
3/// Attempts to load a function from a given library.
4///
5/// This is a small wrapper around `LoadLibrary` and `GetProcAddress`.
6///
7/// # Safety
8///
9/// * Both the library and function names must be valid null-terminated strings.
10pub unsafe fn delay_load<T>(library: crate::PCSTR, function: crate::PCSTR) -> Option<T> {
11 let library: isize = LoadLibraryExA(lplibfilename:library.0, hfile:0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
12
13 if library == 0 {
14 return None;
15 }
16
17 let address: Option isize> = GetProcAddress(hmodule:library, lpprocname:function.0);
18
19 if address.is_some() {
20 return Some(std::mem::transmute_copy(&address));
21 }
22
23 FreeLibrary(hlibmodule:library);
24 None
25}
26