use crate::error::{Error, Result};
use windows::Win32::System::Com::CoTaskMemFree;
use windows::Win32::System::Ole::{OleFlushClipboard, OleInitialize, OleUninitialize};
use windows::Win32::UI::Shell::Common::ITEMIDLIST;
pub struct ComGuard {
_not_send: std::marker::PhantomData<*mut ()>,
}
impl ComGuard {
pub fn new() -> Result<Self> {
unsafe {
OleInitialize(None).map_err(Error::ComInit)?;
}
Ok(Self {
_not_send: std::marker::PhantomData,
})
}
}
impl Drop for ComGuard {
fn drop(&mut self) {
unsafe {
let _ = OleFlushClipboard();
}
unsafe {
OleUninitialize();
}
}
}
pub(crate) struct Pidl {
ptr: *mut ITEMIDLIST,
}
impl Pidl {
pub unsafe fn from_raw(ptr: *mut ITEMIDLIST) -> Self {
Self { ptr }
}
pub fn as_ptr(&self) -> *const ITEMIDLIST {
self.ptr as *const ITEMIDLIST
}
}
impl Drop for Pidl {
fn drop(&mut self) {
if !self.ptr.is_null() {
unsafe {
CoTaskMemFree(Some(self.ptr as *const _));
}
}
}
}