| 1 |
use 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. |
| 10 |
pub unsafe fn delay_load<T>(library: crate::PCSTR, function: crate::PCSTR) -> Option<T> { |
| 11 |
let library = LoadLibraryExA(library.0, 0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); |
| 12 |
|
| 13 |
if library == 0 { |
| 14 |
return None; |
| 15 |
} |
| 16 |
|
| 17 |
let address = GetProcAddress(library, function.0); |
| 18 |
|
| 19 |
if address.is_some() { |
| 20 |
return Some(std::mem::transmute_copy(&address)); |
| 21 |
} |
| 22 |
|
| 23 |
FreeLibrary(library); |
| 24 |
None |
| 25 |
} |