Struct HINSTANCE

Source
pub struct HINSTANCE(/* private fields */);
Available on crate feature kernel only.
Expand description

Handle to an instance, same as HMODULE.

Implementations§

Source§

impl HINSTANCE

Source

pub fn LoadImageBitmap( &self, name: IdObmStr, sz: SIZE, load: LR, ) -> SysResult<DeleteObjectGuard<HBITMAP>>

Available on crate feature gdi only.

LoadImage method for HBITMAP.

Source

pub fn LoadImageCursor( &self, name: IdOcrStr, sz: SIZE, load: LR, ) -> SysResult<DestroyCursorGuard>

Available on crate feature gdi only.

LoadImage method for HCURSOR.

Source

pub fn LoadImageIcon( &self, name: IdOicStr, sz: SIZE, load: LR, ) -> SysResult<DestroyIconGuard>

Available on crate feature gdi only.

LoadImage method for HICON.

Source§

impl HINSTANCE

Source

pub const unsafe fn from_ptr(p: *mut c_void) -> Self

Constructs a new handle object by wrapping a pointer.

This method can be used as an escape hatch to interoperate with other libraries.

§Safety

Be sure the pointer has the correct type and isn’t owned by anyone else, otherwise you may cause memory access violations.

Source

pub const unsafe fn raw_copy(&self) -> Self

Returns a raw copy of the underlying handle pointer.

§Safety

As the name implies, raw_copy returns a raw copy of the handle, so closing one of the copies won’t close the others. This means a handle can be used after it has been closed, what can lead to errors and undefined behavior. Even worse: sometimes Windows reuses handle values, so you can call a method on a completely different handle type, what can be catastrophic.

However, in some cases the Windows API demands a copy of the handle – raw_copy is an escape hatch to fill this gap.

Source

pub const unsafe fn as_mut(&mut self) -> &mut *mut c_void

Returns a mutable reference to the underlying raw pointer.

This method can be used as an escape hatch to interoperate with other libraries.

§Safety

This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.

Source

pub const fn ptr(&self) -> *mut c_void

Returns the underlying raw pointer.

This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.

This method can be used as an escape hatch to interoperate with other libraries.

Source§

impl HINSTANCE

Source

pub fn EnumResourceLanguages<F>( &self, resource_type: RtStr, resource_id: IdStr, func: F, ) -> SysResult<()>
where F: FnMut(LANGID) -> bool,

Source

pub fn EnumResourceNames<F>( &self, resource_type: RtStr, func: F, ) -> SysResult<()>
where F: FnMut(IdStr) -> bool,

EnumResourceNames function.

§Examples
use winsafe::{self as w, prelude::*, co};

let hexe = w::HINSTANCE::LoadLibrary("hand.exe")?;

hexe.EnumResourceTypes(
    |res_type: w::RtStr| -> bool {
        let res_type2 = res_type.clone();
        hexe.EnumResourceNames(
            res_type,
            |name: w::IdStr| -> bool {
                println!("Type: {}, name: {}", res_type2, name);
                true
            },
        ).unwrap();
        true
    },
)?;

// FreeLibrary() called automatically
Source

pub fn EnumResourceTypes<F>(&self, func: F) -> SysResult<()>
where F: FnMut(RtStr) -> bool,

EnumResourceTypes function.

§Examples
use winsafe::{self as w, prelude::*, co};

let hexe = w::HINSTANCE::LoadLibrary("hand.exe")?;

hexe.EnumResourceTypes(
    |res_type: w::RtStr| -> bool {
        println!("Type {}", res_type);
        true
    },
)?;

// FreeLibrary() called automatically
Source

pub fn FindResource( &self, resource_id: IdStr, resource_type: RtStr, ) -> SysResult<HRSRC>

FindResource function.

For an example, see HINSTANCE::LockResource.

Source

pub fn FindResourceEx( &self, resource_id: IdStr, resource_type: RtStr, language: Option<LANGID>, ) -> SysResult<HRSRC>

FindResourceEx function.

For an example, see HINSTANCE::LockResource.

Source

pub fn GetModuleFileName(&self) -> SysResult<String>

GetModuleFileName function.

§Examples

Retrieving the full path of currently running .exe file:

use winsafe::{self as w, prelude::*};

let exe_name = w::HINSTANCE::NULL.GetModuleFileName()?;

println!("EXE: {}", exe_name);
Source

pub fn GetModuleHandle(module_name: Option<&str>) -> SysResult<HINSTANCE>

GetModuleHandle function.

§Examples

Retrieving current module instance:

use winsafe::{self as w, prelude::*};

let hinstance = w::HINSTANCE::GetModuleHandle(None)?;
Source

pub fn GetModuleHandleEx( addr_or_name: AddrStr, flags: GET_MODULE_HANDLE_EX_FLAG, ) -> SysResult<FreeLibraryGuard>

GetModuleHandleEx function.

The GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS is automatically managed by the function.

The GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT flag is never used, for safety reasons.

§Examples
use winsafe::{self as w, prelude::*, co};

let hinstance = w::HINSTANCE::GetModuleHandleEx(
    w::AddrStr::from_str("foo.dll"),
    co::GET_MODULE_HANDLE_EX_FLAG::NoValue,
)?;

// FreeLibrary() called automatically
Source

pub fn GetProcAddress(&self, proc_name: &str) -> SysResult<*const c_void>

GetProcAddress function.

Source

pub fn LoadLibrary(lib_file_name: &str) -> SysResult<FreeLibraryGuard>

LoadLibrary function.

Source

pub fn LoadResource(&self, res_info: &HRSRC) -> SysResult<HRSRCMEM>

LoadResource function.

For an example, see HINSTANCE::LockResource.

Source

pub fn LockResource( &self, res_info: &HRSRC, hres_loaded: &HRSRCMEM, ) -> SysResult<&[u8]>

LockResource function.

This method should belong to HRSRCMEM, but in order to make it safe, we automatically call HINSTANCE::SizeofResource, so it’s implemented here.

§Examples

The Updating Resources example:

use winsafe::{self as w, prelude::*, co};

const IDD_HAND_ABOUTBOX: u16 = 103;
const IDD_FOOT_ABOUTBOX: u16 = 110;

let hexe = w::HINSTANCE::LoadLibrary("hand.exe")?;

let hres = hexe.FindResource(
    w::IdStr::Id(IDD_HAND_ABOUTBOX),
    w::RtStr::Rt(co::RT::DIALOG),
)?;

let hres_load = hexe.LoadResource(&hres)?;
let hres_slice_lock = hexe.LockResource(&hres, &hres_load)?;
let hres_update = w::HUPDATERSRC::BeginUpdateResource("foot.exe", false)?;

hres_update.UpdateResource(
    w::RtStr::Rt(co::RT::DIALOG),
    w::IdStr::Id(IDD_FOOT_ABOUTBOX),
    w::LANGID::NEUTRAL,
    hres_slice_lock,
)?;

// EndUpdateResource() called automatically

// FreeLibrary() called automatically
Source

pub fn SizeofResource(&self, res_info: &HRSRC) -> SysResult<u32>

SizeofResource function.

For an example, see HINSTANCE::LockResource.

Source§

impl HINSTANCE

Source

pub unsafe fn CreateDialogParam( &self, resource_id: IdStr, hwnd_parent: Option<&HWND>, dialog_proc: DLGPROC, init_param: Option<isize>, ) -> SysResult<HWND>

Available on crate feature user only.

CreateDialogParam function.

§Safety

To create a dialog, you must provide a dialog procedure.

Source

pub unsafe fn DialogBoxIndirectParam( &self, dialog_template: &DLGTEMPLATE, hwnd_parent: Option<&HWND>, dialog_proc: DLGPROC, init_param: Option<isize>, ) -> SysResult<isize>

Available on crate feature user only.

DialogBoxIndirectParam function.

§Safety

To create a dialog, you must provide a dialog procedure.

Source

pub unsafe fn DialogBoxParam( &self, resource_id: IdStr, hwnd_parent: Option<&HWND>, dialog_proc: DLGPROC, init_param: Option<isize>, ) -> SysResult<isize>

Available on crate feature user only.

DialogBoxParam function.

§Safety

To create a dialog, you must provide a dialog procedure.

Source

pub fn GetClassInfoEx( &self, class_name: &str, ) -> SysResult<(ATOM, WNDCLASSEX<'_>)>

Available on crate feature user only.

GetClassInfoEx function.

§Examples

Retrieving information of a window class created in our application:

use winsafe::{self as w, prelude::*};

let (atom, wcx) = w::HINSTANCE::GetModuleHandle(None)?
    .GetClassInfoEx("SOME_CLASS_NAME")?;
Source

pub fn LoadAccelerators( &self, table_name: IdStr, ) -> SysResult<DestroyAcceleratorTableGuard>

Available on crate feature user only.

LoadAccelerators function.

Source

pub fn LoadCursor(&self, resource_id: IdIdcStr) -> SysResult<DestroyCursorGuard>

Available on crate feature user only.

LoadCursor function.

§Examples

Loading a system cursor:

use winsafe::{self as w, prelude::*, co};

let sys_cursor = w::HINSTANCE::NULL
    .LoadCursor(w::IdIdcStr::Idc(co::IDC::ARROW))?;
Source

pub fn LoadIcon(&self, icon_id: IdIdiStr) -> SysResult<DestroyIconGuard>

Available on crate feature user only.

LoadIcon function.

§Examples

Loading a system icon:

use winsafe::{self as w, prelude::*, co};

let sys_icon = w::HINSTANCE::NULL
    .LoadIcon(w::IdIdiStr::Idi(co::IDI::INFORMATION))?;
Source

pub fn LoadMenu(&self, resource_id: IdStr) -> SysResult<DestroyMenuGuard>

Available on crate feature user only.

LoadMenu function.

Source

pub fn LoadString(&self, id: u16) -> SysResult<String>

Available on crate feature user only.

LoadString function.

Trait Implementations§

Source§

impl Debug for HINSTANCE

Source§

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

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

impl Display for HINSTANCE

Source§

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

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

impl Handle for HINSTANCE

Source§

const NULL: Self

The null, uninitialized handle; equals to 0.
Source§

const INVALID: Self

The invalid handle; equals to -1. Read more
Source§

unsafe fn from_ptr(p: *mut c_void) -> Self

Constructs a new handle object by wrapping a pointer. Read more
Source§

unsafe fn raw_copy(&self) -> Self

Returns a raw copy of the underlying handle pointer. Read more
Source§

unsafe fn as_mut(&mut self) -> &mut *mut c_void

Returns a mutable reference to the underlying raw pointer. Read more
Source§

fn ptr(&self) -> *mut c_void

Returns the underlying raw pointer. Read more
Source§

fn as_opt(&self) -> Option<&Self>

Returns None if the handle is null or invalid, otherwise returns Some(&self). Read more
Source§

impl Hash for HINSTANCE

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl LowerHex for HINSTANCE

Source§

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

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

impl PartialEq for HINSTANCE

Source§

fn eq(&self, other: &HINSTANCE) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl UpperHex for HINSTANCE

Source§

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

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

impl Eq for HINSTANCE

Source§

impl Send for HINSTANCE

Source§

impl StructuralPartialEq for HINSTANCE

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.