use super::*;
#[repr(transparent)]
pub struct IUnknown(core::ptr::NonNull<core::ffi::c_void>);
#[doc(hidden)]
#[repr(C)]
pub struct IUnknownVtbl {
pub QueryInterface: unsafe extern "system" fn(this: RawPtr, iid: &GUID, interface: *mut RawPtr) -> HRESULT,
pub AddRef: unsafe extern "system" fn(this: RawPtr) -> u32,
pub Release: unsafe extern "system" fn(this: RawPtr) -> u32,
}
unsafe impl Interface for IUnknown {
type Vtable = IUnknownVtbl;
const IID: GUID = GUID::from_u128(0x00000000_0000_0000_c000_000000000046);
}
impl Clone for IUnknown {
fn clone(&self) -> Self {
unsafe {
(self.vtable().AddRef)(core::mem::transmute_copy(self));
}
Self(self.0)
}
}
impl Drop for IUnknown {
fn drop(&mut self) {
unsafe {
(self.vtable().Release)(core::mem::transmute_copy(self));
}
}
}
impl PartialEq for IUnknown {
fn eq(&self, other: &Self) -> bool {
self.cast::<IUnknown>().unwrap().0 == other.cast::<IUnknown>().unwrap().0
}
}
impl Eq for IUnknown {}
impl core::fmt::Debug for IUnknown {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_tuple("IUnknown").field(&self.0).finish()
}
}
pub trait IUnknownImpl {
fn get_impl(&mut self) -> RawPtr;
fn QueryInterface(&mut self, iid: &GUID, interface: *mut RawPtr) -> HRESULT;
fn AddRef(&mut self) -> u32;
fn Release(&mut self) -> u32;
}
#[cfg(feature = "implement")]
impl IUnknownVtbl {
pub const fn new<T: IUnknownImpl, const OFFSET: isize>() -> Self {
unsafe extern "system" fn QueryInterface<T: IUnknownImpl, const OFFSET: isize>(this: RawPtr, iid: &GUID, interface: *mut RawPtr) -> HRESULT {
let this = (this as *mut ::windows::core::RawPtr).offset(OFFSET) as *mut T;
(*this).QueryInterface(iid, interface)
}
unsafe extern "system" fn AddRef<T: IUnknownImpl, const OFFSET: isize>(this: RawPtr) -> u32 {
let this = (this as *mut ::windows::core::RawPtr).offset(OFFSET) as *mut T;
(*this).AddRef()
}
unsafe extern "system" fn Release<T: IUnknownImpl, const OFFSET: isize>(this: RawPtr) -> u32 {
let this = (this as *mut ::windows::core::RawPtr).offset(OFFSET) as *mut T;
(*this).Release()
}
Self { QueryInterface: QueryInterface::<T, OFFSET>, AddRef: AddRef::<T, OFFSET>, Release: Release::<T, OFFSET> }
}
}