Refact, use std::io::Error::from_raw_os_error() to format message

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-11-20 17:22:14 +08:00
parent c85682de8d
commit c6d587f0c7
2 changed files with 26 additions and 8 deletions

View File

@ -173,7 +173,10 @@ impl MagInterface {
if FALSE == init_func() {
return Err(Error::new(
ErrorKind::Other,
format!("Failed to MagInitialize, error: {:?}", Error::last_os_error()),
format!(
"Failed to MagInitialize, error: {:?}",
Error::last_os_error()
),
));
} else {
s.init_succeeded = true;
@ -315,7 +318,10 @@ impl CapturerMag {
) {
return Err(Error::new(
ErrorKind::Other,
format!("Failed to GetModuleHandleExA, error {:?}", Error::last_os_error()),
format!(
"Failed to GetModuleHandleExA, error {:?}",
Error::last_os_error()
),
));
}
@ -342,7 +348,10 @@ impl CapturerMag {
if code != ERROR_CLASS_ALREADY_EXISTS {
return Err(Error::new(
ErrorKind::Other,
format!("Failed to RegisterClassExA, error: {}", code),
format!(
"Failed to RegisterClassExA, error {:?}",
Error::from_raw_os_error(code as _)
),
));
}
}
@ -546,7 +555,10 @@ impl CapturerMag {
if FALSE == set_window_source_func(self.magnifier_window, self.rect) {
return Err(Error::new(
ErrorKind::Other,
format!("Failed to MagSetWindowSource, error {:?}", Error::last_os_error()),
format!(
"Failed to MagSetWindowSource, error {:?}",
Error::last_os_error()
),
));
}
} else {
@ -578,7 +590,10 @@ impl CapturerMag {
unsafe {
if FALSE == DestroyWindow(self.magnifier_window) {
//
println!("Failed DestroyWindow magnifier window, error {:?}", Error::last_os_error())
println!(
"Failed DestroyWindow magnifier window, error {:?}",
Error::last_os_error()
)
}
}
}
@ -588,7 +603,10 @@ impl CapturerMag {
unsafe {
if FALSE == DestroyWindow(self.host_window) {
//
println!("Failed DestroyWindow host window, error {:?}", Error::last_os_error())
println!(
"Failed DestroyWindow host window, error {:?}",
Error::last_os_error()
)
}
}
}

View File

@ -1738,11 +1738,11 @@ pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) ->
{
let last_error = GetLastError();
bail!(
"CreateProcessWithLogonW failed : \"{}\", errno={}",
"CreateProcessWithLogonW failed : \"{}\", error {:?}",
last_error_table
.get(&last_error)
.unwrap_or(&"Unknown error"),
last_error
io::Error::from_raw_os_error(last_error as _)
);
}
}