https://github.com/openbytedev/get-last-error
An error wrapper over Win32 API errors.
https://github.com/openbytedev/get-last-error
error win32
Last synced: 10 months ago
JSON representation
An error wrapper over Win32 API errors.
- Host: GitHub
- URL: https://github.com/openbytedev/get-last-error
- Owner: OpenByteDev
- License: mit
- Created: 2022-02-09T17:06:50.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-09T12:11:30.000Z (almost 4 years ago)
- Last Synced: 2025-06-21T07:19:14.689Z (10 months ago)
- Topics: error, win32
- Language: Rust
- Homepage:
- Size: 9.77 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# get-last-error
[](https://github.com/OpenByteDev/get-last-error/actions/workflows/ci.yml)
[](https://crates.io/crates/get-last-error)
[](https://docs.rs/get-last-error)
[](https://deps.rs/repo/github/openbytedev/get-last-error)
[](https://github.com/OpenByteDev/get-last-error/blob/master/LICENSE)
An error wrapper over Win32 API errors.
## Examples
A `Win32Error` can be constructed from an arbitrary `DWORD`:
```rust
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:
```rust
use get_last_error::Win32Error;
use winapi::um::{winnt::HANDLE, processthreadsapi::OpenProcess};
fn open_process() -> Result {
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](https://github.com/OpenByteDev/get-last-error/blob/master/LICENSE) or http://opensource.org/licenses/MIT)