Struct libloading::os::windows::Library

source ·
pub struct Library(/* private fields */);
Available on Windows only.
Expand description

The platform-specific counterpart of the cross-platform Library.

Implementations§

source§

impl Library

source

pub unsafe fn new<P: AsRef<OsStr>>(filename: P) -> Result<Library, Error>

Find and load a module.

If the filename specifies a full path, the function only searches that path for the module. Otherwise, if the filename specifies a relative path or a module name without a path, the function uses a Windows-specific search strategy to find the module. For more information, see the Remarks on MSDN.

If the filename specifies a library filename without a path and with the extension omitted, the .dll extension is implicitly added. This behaviour may be suppressed by appending a trailing . to the filename.

This is equivalent to Library::load_with_flags(filename, 0).

§Safety

When a library is loaded, initialisation routines contained within the library are executed. For the purposes of safety, the execution of these routines is conceptually the same calling an unknown foreign function and may impose arbitrary requirements on the caller for the call to be sound.

Additionally, the callers of this function must also ensure that execution of the termination routines contained within the library is safe as well. These routines may be executed when the library is unloaded.

source

pub fn this() -> Result<Library, Error>

Get the Library representing the original program executable.

Note that the behaviour of the Library loaded with this method is different from Libraries loaded with os::unix::Library::this. For more information refer to MSDN.

Corresponds to GetModuleHandleExW(0, NULL, _).

source

pub fn open_already_loaded<P: AsRef<OsStr>>( filename: P ) -> Result<Library, Error>

Get a module that is already loaded by the program.

This function returns a Library corresponding to a module with the given name that is already mapped into the address space of the process. If the module isn’t found, an error is returned.

If the filename does not include a full path and there are multiple different loaded modules corresponding to the filename, it is impossible to predict which module handle will be returned. For more information refer to MSDN.

If the filename specifies a library filename without a path and with the extension omitted, the .dll extension is implicitly added. This behaviour may be suppressed by appending a trailing . to the filename.

This is equivalent to GetModuleHandleExW(0, filename, _).

source

pub unsafe fn load_with_flags<P: AsRef<OsStr>>( filename: P, flags: u32 ) -> Result<Library, Error>

Find and load a module, additionally adjusting behaviour with flags.

See Library::new for documentation on the handling of the filename argument. See the flag table on MSDN for information on applicable values for the flags argument.

Corresponds to LoadLibraryExW(filename, reserved: NULL, flags).

§Safety

When a library is loaded, initialisation routines contained within the library are executed. For the purposes of safety, the execution of these routines is conceptually the same calling an unknown foreign function and may impose arbitrary requirements on the caller for the call to be sound.

Additionally, the callers of this function must also ensure that execution of the termination routines contained within the library is safe as well. These routines may be executed when the library is unloaded.

source

pub unsafe fn get<T>(&self, symbol: &[u8]) -> Result<Symbol<T>, Error>

Get a pointer to a function or static variable by symbol name.

The symbol may not contain any null bytes, with the exception of the last byte. A null terminated symbol may avoid a string allocation in some cases.

Symbol is interpreted as-is; no mangling is done. This means that symbols like x::y are most likely invalid.

§Safety

Users of this API must specify the correct type of the function or variable loaded.

source

pub unsafe fn get_ordinal<T>(&self, ordinal: u16) -> Result<Symbol<T>, Error>

Get a pointer to a function or static variable by ordinal number.

§Safety

Users of this API must specify the correct type of the function or variable loaded.

source

pub fn into_raw(self) -> isize

Convert the Library to a raw handle.

source

pub unsafe fn from_raw(handle: isize) -> Library

Convert a raw handle to a Library.

§Safety

The handle must be the result of a successful call of LoadLibraryA, LoadLibraryW, LoadLibraryExW, or LoadLibraryExA, or a handle previously returned by the Library::into_raw call.

source

pub fn close(self) -> Result<(), Error>

Unload the library.

You only need to call this if you are interested in handling any errors that may arise when library is unloaded. Otherwise this will be done when Library is dropped.

The underlying data structures may still get leaked if an error does occur.

Trait Implementations§

source§

impl Debug for Library

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Library

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for Library

source§

impl Sync for Library

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.