use super::*;
use bindings::*;
#[repr(transparent)]
#[derive(Clone, PartialEq, Eq)]
pub struct IInspectable(pub IUnknown);
impl IInspectable {
pub fn GetRuntimeClassName(&self) -> Result<HSTRING> {
unsafe {
let mut abi = core::ptr::null_mut();
(self.vtable().GetRuntimeClassName)(core::mem::transmute_copy(self), &mut abi).ok()?;
Ok(core::mem::transmute(abi))
}
}
}
#[doc(hidden)]
#[repr(C)]
pub struct IInspectableVtbl {
pub base: IUnknownVtbl,
pub GetIids: unsafe extern "system" fn(this: *mut core::ffi::c_void, count: *mut u32, values: *mut *mut GUID) -> HRESULT,
pub GetRuntimeClassName: unsafe extern "system" fn(this: *mut core::ffi::c_void, value: *mut *mut core::ffi::c_void) -> HRESULT,
pub GetTrustLevel: unsafe extern "system" fn(this: *mut core::ffi::c_void, value: *mut i32) -> HRESULT,
}
unsafe impl Interface for IInspectable {
type Vtable = IInspectableVtbl;
const IID: GUID = GUID::from_u128(0xaf86e2e0_b12d_4c6a_9c5a_d7aa65101e90);
}
unsafe impl RuntimeType for IInspectable {
const SIGNATURE: ConstBuffer = ConstBuffer::from_slice(b"cinterface(IInspectable)");
type DefaultType = Option<Self>;
fn from_default(from: &Self::DefaultType) -> Result<Self> {
from.as_ref().cloned().ok_or(Error::OK)
}
}
impl RuntimeName for IInspectable {}
impl core::fmt::Debug for IInspectable {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let name = self.cast::<IStringable>().and_then(|s| s.ToString()).or_else(|_| self.GetRuntimeClassName()).unwrap_or_default();
write!(f, "{:?} {}", self.0, name)
}
}
macro_rules! primitive_boxed_type {
($(($t:ty, $m:ident)),+) => {
$(impl core::convert::TryFrom<$t> for IInspectable {
type Error = Error;
fn try_from(value: $t) -> Result<Self> {
PropertyValue::$m(value)
}
}
impl core::convert::TryFrom<IInspectable> for $t {
type Error = Error;
fn try_from(value: IInspectable) -> Result<Self> {
<IInspectable as Interface>::cast::<IReference<$t>>(&value)?.Value()
}
}
impl core::convert::TryFrom<&IInspectable> for $t {
type Error = Error;
fn try_from(value: &IInspectable) -> Result<Self> {
<IInspectable as Interface>::cast::<IReference<$t>>(value)?.Value()
}
})*
};
}
primitive_boxed_type! {
(bool, CreateBoolean),
(u8, CreateUInt8),
(i16, CreateInt16),
(u16, CreateUInt16),
(i32, CreateInt32),
(u32, CreateUInt32),
(i64, CreateInt64),
(u64, CreateUInt64),
(f32, CreateSingle),
(f64, CreateDouble)
}
impl core::convert::TryFrom<&str> for IInspectable {
type Error = Error;
fn try_from(value: &str) -> Result<Self> {
let value: HSTRING = value.into();
PropertyValue::CreateString(value)
}
}
impl core::convert::TryFrom<HSTRING> for IInspectable {
type Error = Error;
fn try_from(value: HSTRING) -> Result<Self> {
PropertyValue::CreateString(value)
}
}
impl core::convert::TryFrom<&HSTRING> for IInspectable {
type Error = Error;
fn try_from(value: &HSTRING) -> Result<Self> {
PropertyValue::CreateString(value)
}
}
impl core::convert::TryFrom<IInspectable> for HSTRING {
type Error = Error;
fn try_from(value: IInspectable) -> Result<Self> {
<IInspectable as Interface>::cast::<IReference<HSTRING>>(&value)?.Value()
}
}
impl core::convert::TryFrom<&IInspectable> for HSTRING {
type Error = Error;
fn try_from(value: &IInspectable) -> Result<Self> {
<IInspectable as Interface>::cast::<IReference<HSTRING>>(value)?.Value()
}
}
#[cfg(feature = "implement")]
impl IInspectableVtbl {
pub const fn new<Identity: IUnknownImpl, Name: RuntimeName, const OFFSET: isize>() -> Self {
unsafe extern "system" fn GetIids(_: *mut core::ffi::c_void, count: *mut u32, values: *mut *mut GUID) -> ::windows::core::HRESULT {
*count = 0;
*values = core::ptr::null_mut();
HRESULT(0)
}
unsafe extern "system" fn GetRuntimeClassName<T: RuntimeName>(_: *mut core::ffi::c_void, value: *mut *mut core::ffi::c_void) -> HRESULT {
let h: HSTRING = T::NAME.into(); *value = ::core::mem::transmute(h);
HRESULT(0)
}
unsafe extern "system" fn GetTrustLevel(_: *mut core::ffi::c_void, value: *mut i32) -> HRESULT {
*value = 0;
HRESULT(0)
}
Self { base: IUnknownVtbl::new::<Identity, OFFSET>(), GetIids, GetRuntimeClassName: GetRuntimeClassName::<Name>, GetTrustLevel }
}
}