Trait winsafe::prelude::kernel_Hinstance

source ·
pub trait kernel_Hinstance: Handle {
    // Provided methods
    fn EnumResourceLanguages<F>(
        &self,
        resource_type: RtStr,
        resource_id: IdStr,
        func: F
    ) -> SysResult<()>
       where F: FnMut(LANGID) -> bool { ... }
    fn EnumResourceNames<F>(
        &self,
        resource_type: RtStr,
        func: F
    ) -> SysResult<()>
       where F: FnMut(IdStr) -> bool { ... }
    fn EnumResourceTypes<F>(&self, func: F) -> SysResult<()>
       where F: FnMut(RtStr) -> bool { ... }
    fn FindResource(
        &self,
        resource_id: IdStr,
        resource_type: RtStr
    ) -> SysResult<HRSRC> { ... }
    fn FindResourceEx(
        &self,
        resource_id: IdStr,
        resource_type: RtStr,
        language: Option<LANGID>
    ) -> SysResult<HRSRC> { ... }
    fn GetModuleFileName(&self) -> SysResult<String> { ... }
    fn GetModuleHandle(module_name: Option<&str>) -> SysResult<HINSTANCE> { ... }
    fn GetProcAddress(&self, proc_name: &str) -> SysResult<*const c_void> { ... }
    fn LoadLibrary(lib_file_name: &str) -> SysResult<FreeLibraryGuard> { ... }
    fn LoadResource(&self, res_info: &HRSRC) -> SysResult<HRSRCMEM> { ... }
    fn LockResource(
        &self,
        res_info: &HRSRC,
        hres_loaded: &HRSRCMEM
    ) -> SysResult<&[u8]> { ... }
    fn SizeofResource(&self, res_info: &HRSRC) -> SysResult<u32> { ... }
}
Available on crate feature kernel only.
Expand description

This trait is enabled with the kernel feature, and provides methods for HINSTANCE.

Prefer importing this trait through the prelude:

use winsafe::prelude::*;

Provided Methods§

source

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

source

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

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

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

FindResource function.

For an example, see HINSTANCE::LockResource.

source

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

FindResourceEx function.

For an example, see HINSTANCE::LockResource.

source

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

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

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

GetProcAddress function.

source

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

LoadLibrary function.

source

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

LoadResource function.

For an example, see HINSTANCE::LockResource.

source

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::new(co::LANG::NEUTRAL, co::SUBLANG::NEUTRAL),
    hres_slice_lock,
)?;

// EndUpdateResource() called automatically

// FreeLibrary() called automatically
source

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

SizeofResource function.

For an example, see HINSTANCE::LockResource.

Object Safety§

This trait is not object safe.

Implementors§