Skip to content

Commit

Permalink
fix bad error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Feb 7, 2024
1 parent 79086cd commit 22a619a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ pub enum InterfaceGetterError<'a> {
#[error(transparent)]
InvalidFunctionCString(#[from] NulError),

/// when the dll doesn't have a create iterface
#[error("dll {0} doesn't have a create interface function")]
NullCreateInterface(usize),

/// an error from the win api yay
#[error(transparent)]
WinApiError(#[from] windows::core::Error),
Expand Down
10 changes: 2 additions & 8 deletions src/interfaces/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ pub trait SourceInterface<Rtrn = Self> {
unsafe {
let create_interface = std::mem::transmute::<_, CreateInterface>(
GetProcAddress(dll_ptr, PCSTR("CreateInterface\0".as_ptr())).ok_or(
windows::core::Error::new(
windows::core::HRESULT(0x0000271E),
"A required pointer is null.".into(),
),
InterfaceGetterError::NullCreateInterface(dll_ptr.0 as usize),
)?,
);

Expand Down Expand Up @@ -143,10 +140,7 @@ pub trait SourceInterface<Rtrn = Self> {
GetModuleHandleA(PCSTR(dll_name.as_ptr() as *const u8))?,
PCSTR("CreateInterface\0".as_ptr()),
)
.ok_or(windows::core::Error::new(
windows::core::HRESULT(0x0000271E),
"A required pointer is null.".into(),
))?,
.ok_or(InterfaceGetterError::NullCreateInterface(0x0))?,
);

let cstring_interface_name = try_cstring(interface_name)?;
Expand Down

0 comments on commit 22a619a

Please sign in to comment.