pub struct ModuleHandle(/* private fields */);
Expand description
A handle that obtains and holds the address of the surviving dll/exe until the end of program execution.
§undefined behavior
If Self::new
specifies a dll/exe that does not live until the end of program execution
Implementations§
Source§impl ModuleHandle
impl ModuleHandle
Sourcepub unsafe fn new<H>(module_name: H) -> Result<Self, ModuleHandleError>
pub unsafe fn new<H>(module_name: H) -> Result<Self, ModuleHandleError>
Gets the module handle of a module (exe, dll, etc.) that is being loaded by the calling process.
§Example
use commonlibsse_ng::rel::module::ModuleHandle;
use windows::core::h; // `h!` is utf-16 str macro.
let handle = unsafe { ModuleHandle::new(h!("kernel32.dll")) };
assert!(handle.is_ok());
// If there is no extension, a `.dll` is automatically specified.(This is the behavior of `GetModuleHandleW` function.)
let handle = unsafe { ModuleHandle::new(h!("kernel32")) };
assert!(handle.is_ok());
§Errors
- Errors if a module is specified that is not loaded by the calling process.
- If the specified module handle could not be obtained.
§Safety
It is safe as long as specify a dll/exe that survives the 'static
life time.
Sourcepub const fn try_as_nt_header(
&self,
) -> Result<&IMAGE_NT_HEADERS64, ModuleHandleError>
pub const fn try_as_nt_header( &self, ) -> Result<&IMAGE_NT_HEADERS64, ModuleHandleError>
Trait Implementations§
Source§impl Clone for ModuleHandle
impl Clone for ModuleHandle
Source§fn clone(&self) -> ModuleHandle
fn clone(&self) -> ModuleHandle
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ModuleHandle
impl Debug for ModuleHandle
Source§impl Default for ModuleHandle
impl Default for ModuleHandle
Source§impl Hash for ModuleHandle
impl Hash for ModuleHandle
Source§impl Ord for ModuleHandle
impl Ord for ModuleHandle
Source§fn cmp(&self, other: &ModuleHandle) -> Ordering
fn cmp(&self, other: &ModuleHandle) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for ModuleHandle
impl PartialEq for ModuleHandle
Source§impl PartialOrd for ModuleHandle
impl PartialOrd for ModuleHandle
impl Copy for ModuleHandle
impl Eq for ModuleHandle
impl Send for ModuleHandle
impl StructuralPartialEq for ModuleHandle
impl Sync for ModuleHandle
Auto Trait Implementations§
impl Freeze for ModuleHandle
impl RefUnwindSafe for ModuleHandle
impl Unpin for ModuleHandle
impl UnwindSafe for ModuleHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more