ComWrapper

Struct ComWrapper 

Source
pub struct ComWrapper<C>
where C: Class,
{ /* private fields */ }
Expand description

A wrapper for constructing a reference-counted COM object from a Rust value.

ComWrapper represents an owning reference to the COM object, i.e. it will decrement the object’s reference count when it goes out of scope.

Implementations§

Source§

impl<C> ComWrapper<C>
where C: Class,

Source

pub fn new(data: C) -> ComWrapper<C>
where C: 'static, <C as Class>::Interfaces: MakeHeader<C, ComWrapper<C>>,

Allocates memory for an object and its header and places data into it.

Examples found in repository?
examples/gain.rs (line 529)
521    unsafe fn createInstance(
522        &self,
523        cid: FIDString,
524        iid: FIDString,
525        obj: *mut *mut c_void,
526    ) -> tresult {
527        let instance = match *(cid as *const TUID) {
528            GainProcessor::CID => Some(
529                ComWrapper::new(GainProcessor::new())
530                    .to_com_ptr::<FUnknown>()
531                    .unwrap(),
532            ),
533            GainController::CID => Some(
534                ComWrapper::new(GainController::new())
535                    .to_com_ptr::<FUnknown>()
536                    .unwrap(),
537            ),
538            _ => None,
539        };
540
541        if let Some(instance) = instance {
542            let ptr = instance.as_ptr();
543            ((*(*ptr).vtbl).queryInterface)(ptr, iid as *mut TUID, obj)
544        } else {
545            kInvalidArgument
546        }
547    }
548}
549
550#[cfg(target_os = "windows")]
551#[no_mangle]
552extern "system" fn InitDll() -> bool {
553    true
554}
555
556#[cfg(target_os = "windows")]
557#[no_mangle]
558extern "system" fn ExitDll() -> bool {
559    true
560}
561
562#[cfg(target_os = "macos")]
563#[no_mangle]
564extern "system" fn BundleEntry(_bundle_ref: *mut c_void) -> bool {
565    true
566}
567
568#[cfg(target_os = "macos")]
569#[no_mangle]
570extern "system" fn BundleExit() -> bool {
571    true
572}
573
574#[cfg(target_os = "linux")]
575#[no_mangle]
576extern "system" fn ModuleEntry(_library_handle: *mut c_void) -> bool {
577    true
578}
579
580#[cfg(target_os = "linux")]
581#[no_mangle]
582extern "system" fn ModuleExit() -> bool {
583    true
584}
585
586#[no_mangle]
587extern "system" fn GetPluginFactory() -> *mut IPluginFactory {
588    ComWrapper::new(Factory {})
589        .to_com_ptr::<IPluginFactory>()
590        .unwrap()
591        .into_raw()
592}
Source

pub fn as_com_ref<'a, I>(&'a self) -> Option<ComRef<'a, I>>
where I: Interface,

If I is in C’s interface list, returns a ComRef<I> pointing to the object.

Does not perform any reference counting operations.

Source

pub fn to_com_ptr<I>(&self) -> Option<ComPtr<I>>
where I: Interface,

If I is in C’s interface list, returns a ComPtr<I> pointing to the object.

If a ComPtr is returned, the object’s reference count will be incremented.

Examples found in repository?
examples/gain.rs (line 530)
521    unsafe fn createInstance(
522        &self,
523        cid: FIDString,
524        iid: FIDString,
525        obj: *mut *mut c_void,
526    ) -> tresult {
527        let instance = match *(cid as *const TUID) {
528            GainProcessor::CID => Some(
529                ComWrapper::new(GainProcessor::new())
530                    .to_com_ptr::<FUnknown>()
531                    .unwrap(),
532            ),
533            GainController::CID => Some(
534                ComWrapper::new(GainController::new())
535                    .to_com_ptr::<FUnknown>()
536                    .unwrap(),
537            ),
538            _ => None,
539        };
540
541        if let Some(instance) = instance {
542            let ptr = instance.as_ptr();
543            ((*(*ptr).vtbl).queryInterface)(ptr, iid as *mut TUID, obj)
544        } else {
545            kInvalidArgument
546        }
547    }
548}
549
550#[cfg(target_os = "windows")]
551#[no_mangle]
552extern "system" fn InitDll() -> bool {
553    true
554}
555
556#[cfg(target_os = "windows")]
557#[no_mangle]
558extern "system" fn ExitDll() -> bool {
559    true
560}
561
562#[cfg(target_os = "macos")]
563#[no_mangle]
564extern "system" fn BundleEntry(_bundle_ref: *mut c_void) -> bool {
565    true
566}
567
568#[cfg(target_os = "macos")]
569#[no_mangle]
570extern "system" fn BundleExit() -> bool {
571    true
572}
573
574#[cfg(target_os = "linux")]
575#[no_mangle]
576extern "system" fn ModuleEntry(_library_handle: *mut c_void) -> bool {
577    true
578}
579
580#[cfg(target_os = "linux")]
581#[no_mangle]
582extern "system" fn ModuleExit() -> bool {
583    true
584}
585
586#[no_mangle]
587extern "system" fn GetPluginFactory() -> *mut IPluginFactory {
588    ComWrapper::new(Factory {})
589        .to_com_ptr::<IPluginFactory>()
590        .unwrap()
591        .into_raw()
592}

Trait Implementations§

Source§

impl<C> Clone for ComWrapper<C>
where C: Class,

Source§

fn clone(&self) -> ComWrapper<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C> Deref for ComWrapper<C>
where C: Class,

Source§

type Target = C

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<ComWrapper<C> as Deref>::Target

Dereferences the value.
Source§

impl<C> Wrapper<C> for ComWrapper<C>
where C: Class,

Source§

unsafe fn data_from_header( ptr: *mut <<C as Class>::Interfaces as InterfaceList>::Header, ) -> *mut C

Given a pointer to an object’s header, returns a pointer to the object itself.
Source§

unsafe fn header_from_data( ptr: *mut C, ) -> *mut <<C as Class>::Interfaces as InterfaceList>::Header

Given a pointer to an object, returns a pointer to the object’s header.
Source§

unsafe fn add_ref(ptr: *mut C) -> usize

Increments the reference count of an object and returns the resulting count.
Source§

unsafe fn release(ptr: *mut C) -> usize

Decrements the reference count of an object and returns the resulting count.
Source§

impl<C> Send for ComWrapper<C>
where C: Class + Send + Sync,

Source§

impl<C> Sync for ComWrapper<C>
where C: Class + Send + Sync,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.