windows_helpers/
foundation.rs1#![cfg(feature = "f_Win32_Foundation")]
2
3use crate::windows;
4use windows::Win32::Foundation::{E_FAIL, LPARAM};
5
6pub trait BoolExt {
7 fn ok_or_e_fail(self) -> windows::core::Result<()>;
9}
10
11impl BoolExt for windows::Win32::Foundation::BOOL {
12 fn ok_or_e_fail(self) -> windows::core::Result<()> {
13 if self.as_bool() {
14 Ok(())
15 } else {
16 Err(E_FAIL.into())
17 }
18 }
19}
20
21pub trait LParamExt {
22 unsafe fn cast_to_ref<T>(&self) -> &T;
23 unsafe fn cast_to_mut<T>(&mut self) -> &mut T;
24}
25
26impl LParamExt for LPARAM {
27 unsafe fn cast_to_ref<T>(&self) -> &T {
28 &*(self.0 as *const T)
29 }
30
31 unsafe fn cast_to_mut<T>(&mut self) -> &mut T {
32 &mut *(self.0 as *mut T)
33 }
34}