Crates.io | windows_safe_handle |
lib.rs | windows_safe_handle |
version | 0.1.2 |
source | src |
created_at | 2023-09-02 05:26:10.490175 |
updated_at | 2023-09-02 05:45:12.872574 |
description | Generate smart pointers for https://crates.io/crates/windows raw handles with ergonomic APIs. |
homepage | |
repository | https://github.com/vsrs/windows_safe_handle |
max_upload_size | |
id | 961542 |
size | 10,363 |
Generate smart pointers for windows raw handles with ergonomic APIs.
This crate doesn't offer pre-defined smart pointers. Instead, it provides a single [safe_handle!
] macro for generation:
Drop
use windows_safe_handle::safe_handle;
use windows::Win32::Foundation::{HANDLE, CloseHandle};
safe_handle!(pub Handle(HANDLE), CloseHandle);
If you do not need to export the Handle
type, simply omit the pub
keyword.
Drop
logicYou can use a closure-based syntax:
use windows_safe_handle::safe_handle;
use windows::Win32::Foundation::{HANDLE, CloseHandle};
safe_handle!(pub Handle(HANDLE), |h| {
// Place your code here
unsafe { CloseHandle(h) }
});
Note that in this case you have to explicitly use unsafe
block.
Refer to tests/bcrypt_hash.rs
to see how to safely wrap Windows Cryptography Next Generation (CNG) APIs for calculating MD5 hashes.