dxgi_win::com_interface! [] [src]

macro_rules! com_interface {
	(
		$interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) {$(
			fn $method:ident(&mut self $(,$arg:ident : $argty:ty)*) -> $retty:ty
		),*}
	) => {
		#[repr(C)]
		pub struct $vtbl {
			pub parent: $pvtbl,
			$(pub $method:
				Option<unsafe extern "system" fn(This: *mut $interface $(,$arg: $argty)*) -> $retty>
			),*
		}
		#[repr(C)]
		pub struct $interface {
			pub lpVtbl: *const $vtbl
		}
		impl $interface {
			$(pub unsafe fn $method(&mut self $(,$arg: $argty)*) -> $retty {
				((*self.lpVtbl).$method.unwrap())(self $(,$arg)*)
			})*
		}
		impl ::std::ops::Deref for $interface {
			type Target = $pinterface;
			fn deref(&self) -> &$pinterface {
				unsafe { ::std::mem::transmute(self) }
			}
		}
		impl ::std::ops::DerefMut for $interface {
			fn deref_mut(&mut self) -> &mut $pinterface {
				unsafe { ::std::mem::transmute(self) }
			}
		}
		impl COMInterface for $interface {
			fn i_unknown(&self) -> &IUnknown { &*self }
			fn i_unknown_mut(&mut self) -> &mut IUnknown { &mut *self }
		}
	};
}