decl_class_vtable

Macro decl_class_vtable 

Source
macro_rules! decl_class_vtable {
    ($id:ident, $($itfs: ident),+ $(,)?) => { ... };
    (EXPAND_DISPATCH $id:ident ($idx:expr) $head:ident $($tail:ident)*, Self { $($names:ident: $v:expr,)* }) => { ... };
    (EXPAND_DISPATCH $id:ident ($idx:expr), Self { $($names:ident: $v:expr,)* }) => { ... };
}
Expand description

Declares a vtable for a COM class.

The defined type will be named like the class, with Vtbl appended. The macro is called with the first argument being the class name, and subsequent arguments being the implemented interfaces. For each of the listed interfaces, the class must implement the corresponding Impl trait, for example IUnknownImpl.

The resulting vtable struct will contain all the interface vtables for the class, and have a single associated function, get, which returns the vtable instance for the class. See IUnknownVtbl::dispatch for more information on how to use these vtables.

§Example

use nucomcore::idl::iunknown::IUnknownImpl;

decl_class_vtable!(Foo, IFoo, IBar);

struct Foo {
    vtbl: FooVtbl,
    rc: u32,
}

impl Foo {
    pub fn new() -> *mut IUnknown {
        Box::into_raw(Box::new(Foo {
            vtbl: FooVtbl::get(),
            rc: 1,
        })) as *mut _
    }
}

impl IUnknownImpl for Foo { /* ... */ }
impl IFooImpl for Foo { /* ... */ }
impl IBarImpl for Foo { /* ... */ }