use crate::decl::*;
use crate::guard::*;
use crate::prelude::*;
pub struct VersionInfoGuard {
handle: HVERSIONINFO,
}
impl Drop for VersionInfoGuard {
fn drop(&mut self) {
if let Some(h) = self.handle.as_opt() {
let hglobal_ptr = unsafe { HGLOBAL::from_ptr(h.ptr()) };
let _ = unsafe { GlobalFreeGuard::new(hglobal_ptr) };
}
}
}
impl std::ops::Deref for VersionInfoGuard {
type Target = HVERSIONINFO;
fn deref(&self) -> &Self::Target {
&self.handle
}
}
impl std::ops::DerefMut for VersionInfoGuard {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.handle
}
}
impl VersionInfoGuard {
#[must_use]
pub const unsafe fn new(handle: HVERSIONINFO) -> Self {
Self { handle }
}
#[must_use]
pub fn leak(&mut self) -> HVERSIONINFO {
std::mem::replace(&mut self.handle, Handle::INVALID)
}
}