#winapi #win32 #error #ffi

no-std get-last-error

An error wrapper over Win32 API errors

2 releases

0.1.1 Jul 9, 2022
0.1.0 Feb 9, 2022

#114 in Windows APIs

Download history 1/week @ 2023-06-08 23/week @ 2023-06-15 20/week @ 2023-06-22 27/week @ 2023-06-29 32/week @ 2023-07-06 14/week @ 2023-07-13 95/week @ 2023-07-20 15/week @ 2023-07-27 12/week @ 2023-08-03 15/week @ 2023-08-10 18/week @ 2023-08-17 11/week @ 2023-08-24 10/week @ 2023-08-31 19/week @ 2023-09-07 11/week @ 2023-09-14 9/week @ 2023-09-21

52 downloads per month
Used in 3 crates

MIT license

10KB
137 lines

get-last-error

CI crates.io Documentation dependency status MIT

An error wrapper over Win32 API errors.

Examples

A Win32Error can be constructed from an arbitrary DWORD:

use get_last_error::Win32Error;

let err = Win32Error::new(0);
println!("{}", err); // prints "The operation completed successfully."

The Win32Error::get_last_error retrieves the last error code for the current thread:

use get_last_error::Win32Error;
use winapi::um::{winnt::HANDLE, processthreadsapi::OpenProcess};

fn open_process() -> Result<HANDLE, Win32Error> {
    let result = unsafe { OpenProcess(0, 0, 0) }; // some windows api call
    if result.is_null() { // null indicates failure.
        Err(Win32Error::get_last_error())
    } else {
        Ok(result)
    }
}

License

Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)

Dependencies

~175KB