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,
impl<C> ComWrapper<C>where
C: Class,
Sourcepub fn new(data: C) -> ComWrapper<C>
pub fn new(data: 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}Sourcepub fn as_com_ref<'a, I>(&'a self) -> Option<ComRef<'a, I>>where
I: Interface,
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.
Sourcepub fn to_com_ptr<I>(&self) -> Option<ComPtr<I>>where
I: Interface,
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,
impl<C> Clone for ComWrapper<C>where
C: Class,
Source§fn clone(&self) -> ComWrapper<C>
fn clone(&self) -> ComWrapper<C>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<C> Deref for ComWrapper<C>where
C: Class,
impl<C> Deref for ComWrapper<C>where
C: Class,
Source§impl<C> Wrapper<C> for ComWrapper<C>where
C: Class,
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
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
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.
impl<C> Send for ComWrapper<C>
impl<C> Sync for ComWrapper<C>
Auto Trait Implementations§
impl<C> Freeze for ComWrapper<C>
impl<C> RefUnwindSafe for ComWrapper<C>
impl<C> Unpin for ComWrapper<C>
impl<C> UnwindSafe for ComWrapper<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more