pub struct HINSTANCE(/* private fields */);kernel only.Expand description
Handle to an
instance,
same as HMODULE.
Implementations§
Source§impl HINSTANCE
impl HINSTANCE
Sourcepub fn LoadImageBitmap(
&self,
name: IdObmStr,
sz: SIZE,
load: LR,
) -> SysResult<DeleteObjectGuard<HBITMAP>>
Available on crate feature gdi only.
pub fn LoadImageBitmap( &self, name: IdObmStr, sz: SIZE, load: LR, ) -> SysResult<DeleteObjectGuard<HBITMAP>>
gdi only.Sourcepub fn LoadImageCursor(
&self,
name: IdOcrStr,
sz: SIZE,
load: LR,
) -> SysResult<DestroyCursorGuard>
Available on crate feature gdi only.
pub fn LoadImageCursor( &self, name: IdOcrStr, sz: SIZE, load: LR, ) -> SysResult<DestroyCursorGuard>
gdi only.Sourcepub fn LoadImageIcon(
&self,
name: IdOicStr,
sz: SIZE,
load: LR,
) -> SysResult<DestroyIconGuard>
Available on crate feature gdi only.
pub fn LoadImageIcon( &self, name: IdOicStr, sz: SIZE, load: LR, ) -> SysResult<DestroyIconGuard>
gdi only.Source§impl HINSTANCE
impl HINSTANCE
Sourcepub const unsafe fn from_ptr(p: *mut c_void) -> Self
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.
Sourcepub const unsafe fn raw_copy(&self) -> Self
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.
Sourcepub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
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.
Sourcepub const fn ptr(&self) -> *mut c_void
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
impl HINSTANCE
Sourcepub fn EnumResourceLanguages<F>(
&self,
resource_type: RtStr,
resource_id: IdStr,
func: F,
) -> SysResult<()>
pub fn EnumResourceLanguages<F>( &self, resource_type: RtStr, resource_id: IdStr, func: F, ) -> SysResult<()>
EnumResourceLanguages
function.
Sourcepub fn EnumResourceNames<F>(
&self,
resource_type: RtStr,
func: F,
) -> SysResult<()>
pub fn EnumResourceNames<F>( &self, resource_type: RtStr, func: F, ) -> SysResult<()>
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 automaticallySourcepub fn EnumResourceTypes<F>(&self, func: F) -> SysResult<()>
pub fn EnumResourceTypes<F>(&self, func: F) -> SysResult<()>
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 automaticallySourcepub fn FindResource(
&self,
resource_id: IdStr,
resource_type: RtStr,
) -> SysResult<HRSRC>
pub fn FindResource( &self, resource_id: IdStr, resource_type: RtStr, ) -> SysResult<HRSRC>
FindResource
function.
For an example, see
HINSTANCE::LockResource.
Sourcepub fn FindResourceEx(
&self,
resource_id: IdStr,
resource_type: RtStr,
language: Option<LANGID>,
) -> SysResult<HRSRC>
pub fn FindResourceEx( &self, resource_id: IdStr, resource_type: RtStr, language: Option<LANGID>, ) -> SysResult<HRSRC>
FindResourceEx
function.
For an example, see
HINSTANCE::LockResource.
Sourcepub fn GetModuleFileName(&self) -> SysResult<String>
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);Sourcepub fn GetModuleHandle(module_name: Option<&str>) -> SysResult<HINSTANCE>
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)?;Sourcepub fn GetModuleHandleEx(
addr_or_name: AddrStr,
flags: GET_MODULE_HANDLE_EX_FLAG,
) -> SysResult<FreeLibraryGuard>
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 automaticallySourcepub fn GetProcAddress(&self, proc_name: &str) -> SysResult<*const c_void>
pub fn GetProcAddress(&self, proc_name: &str) -> SysResult<*const c_void>
GetProcAddress
function.
Sourcepub fn LoadLibrary(lib_file_name: &str) -> SysResult<FreeLibraryGuard>
pub fn LoadLibrary(lib_file_name: &str) -> SysResult<FreeLibraryGuard>
LoadLibrary
function.
Sourcepub fn LoadResource(&self, res_info: &HRSRC) -> SysResult<HRSRCMEM>
pub fn LoadResource(&self, res_info: &HRSRC) -> SysResult<HRSRCMEM>
LoadResource
function.
For an example, see
HINSTANCE::LockResource.
Sourcepub fn LockResource(
&self,
res_info: &HRSRC,
hres_loaded: &HRSRCMEM,
) -> SysResult<&[u8]>
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 automaticallySourcepub fn SizeofResource(&self, res_info: &HRSRC) -> SysResult<u32>
pub fn SizeofResource(&self, res_info: &HRSRC) -> SysResult<u32>
SizeofResource
function.
For an example, see
HINSTANCE::LockResource.
Source§impl HINSTANCE
impl HINSTANCE
Sourcepub 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.
pub unsafe fn CreateDialogParam( &self, resource_id: IdStr, hwnd_parent: Option<&HWND>, dialog_proc: DLGPROC, init_param: Option<isize>, ) -> SysResult<HWND>
user only.Sourcepub 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.
pub unsafe fn DialogBoxIndirectParam( &self, dialog_template: &DLGTEMPLATE, hwnd_parent: Option<&HWND>, dialog_proc: DLGPROC, init_param: Option<isize>, ) -> SysResult<isize>
user only.Sourcepub 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.
pub unsafe fn DialogBoxParam( &self, resource_id: IdStr, hwnd_parent: Option<&HWND>, dialog_proc: DLGPROC, init_param: Option<isize>, ) -> SysResult<isize>
user only.Sourcepub fn GetClassInfoEx(
&self,
class_name: &str,
) -> SysResult<(ATOM, WNDCLASSEX<'_>)>
Available on crate feature user only.
pub fn GetClassInfoEx( &self, class_name: &str, ) -> SysResult<(ATOM, WNDCLASSEX<'_>)>
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")?;Sourcepub fn LoadAccelerators(
&self,
table_name: IdStr,
) -> SysResult<DestroyAcceleratorTableGuard>
Available on crate feature user only.
pub fn LoadAccelerators( &self, table_name: IdStr, ) -> SysResult<DestroyAcceleratorTableGuard>
user only.LoadAccelerators
function.
Sourcepub fn LoadCursor(&self, resource_id: IdIdcStr) -> SysResult<DestroyCursorGuard>
Available on crate feature user only.
pub fn LoadCursor(&self, resource_id: IdIdcStr) -> SysResult<DestroyCursorGuard>
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))?;Sourcepub fn LoadIcon(&self, icon_id: IdIdiStr) -> SysResult<DestroyIconGuard>
Available on crate feature user only.
pub fn LoadIcon(&self, icon_id: IdIdiStr) -> SysResult<DestroyIconGuard>
user only.Sourcepub fn LoadMenu(&self, resource_id: IdStr) -> SysResult<DestroyMenuGuard>
Available on crate feature user only.
pub fn LoadMenu(&self, resource_id: IdStr) -> SysResult<DestroyMenuGuard>
user only.LoadMenu
function.
Sourcepub fn LoadString(&self, id: u16) -> SysResult<String>
Available on crate feature user only.
pub fn LoadString(&self, id: u16) -> SysResult<String>
user only.LoadString
function.