pacemaker 3.0.3
COM automation for people with deadlines and a hatred of GUIs
 
Loading...
Searching...
No Matches
COMProxy< T > Class Template Reference

Owning smart-pointer base class for COM dispatch proxy objects. More...

#include <COMProxy.hpp>

Inheritance diagram for COMProxy< T >:
Collaboration diagram for COMProxy< T >:

Public Member Functions

 COMProxy ()=default
 Default ctor; leaves the internal pointer null.
 
 COMProxy (::IDispatch *subject)
 Constrcuts the proxy from a raw IDispatch*, taking ownership.
 
 COMProxy (unique_com_ptr<::IDispatch > subject)
 Constructs the proxy by narrowing an owning IDispatch pointer to T.
 
 COMProxy (COMProxy &&)=default
 Move ctor; transfers ownership of the COM pointer.
 
COMProxyoperator= (COMProxy &&)=default
 Move assignment; transfers ownership of the COM pointer.
 

Detailed Description

template<class T>
class pacemaker::inca::detail::COMProxy< T >

Owning smart-pointer base class for COM dispatch proxy objects.

COMProxy<T> publicly inherits unique_com_ptr<T>, making every instantiated proxy type an owning smart pointer. Proxy types are declared as type aliases:

Owning smart-pointer base class for COM dispatch proxy objects.
Definition COMProxy.hpp:58

T must be a "DispatchWrapper" struct, i.e. a struct that:

  • publicly inherits the corresponding raw COM dispatch type, and
  • declares using type = ::RawDispatchType.

The type typedef is consumed by query_interface<T>, which uses __uuidof(T::type) to call QueryInterface with the correct interface identifier.

Constructors

Three ctors are provided:

  • Default: leaves the pointer null; required so proxy type aliases can be default-constructed before being move-assigned (e.g. when stored as class members initialised in a constrcutor body).
  • Raw IDispatch*: convenience overload that wraps the pointer in a unique_com_ptr<IDispatch> and delegates to the owning ctor.
  • unique_com_ptr<IDispatch>: takes ownership of the supplied generic pointer and narrows it to T via query_interface<T>.

Copy construction and copy assignment are implicitly deleted by the unique_ptr base, preventing accidental duplication of COM reference counts. Move construction and move assignment are defaulted.

Typical usage

// Obtain a raw IDispatch from CoCreateInstance or a COM method, then:
FooProxy proxy{rawIDispatch}; // narrows via QueryInterface
proxy->SomeCOMMethod(); // operator-> reaches Foo_DispatchWrapper
::Foo_Dispatch *raw = proxy.get() // non-owning raw pointer
Template Parameters
TA DispatchWrapper struct that publicly inherits a COM dispatch type and declares using type = <raw dispatch type>.
See also
pacemaker::inca::detail::unique_com_ptr
pacemaker::inca::detail::query_interface

Definition at line 57 of file COMProxy.hpp.

Constructor & Destructor Documentation

◆ COMProxy() [1/4]

template<class T >
COMProxy ( )
default

Default ctor; leaves the internal pointer null.

A null proxy compares equal to nullptr via the inherited unique_ptr::operator bool(). It must be populated by move-assignment before any COM methods are invoked through it.

◆ COMProxy() [2/4]

template<class T >
COMProxy ( ::IDispatch * subject)
inlineexplicit

Constrcuts the proxy from a raw IDispatch*, taking ownership.

Wraps subject in a unique_com_ptr<IDispatch> and delegates to the owning ctor, which calls query_interface<T> to narrow the pointer to T.

Parameters
subjectRaw IDispatch pointer obtained from a COM call. Ownership is transferred to the proxy; the caller must not call Release() on it afterwards.
Exceptions
std::invalid_argumentif subject is null.
std::runtime_errorif QueryInterface forT::type` fails.

Definition at line 83 of file COMProxy.hpp.

◆ COMProxy() [3/4]

template<class T >
COMProxy ( unique_com_ptr<::IDispatch > subject)
inlineexplicit

Constructs the proxy by narrowing an owning IDispatch pointer to T.

Calls query_interface<T>(std::move(subject)) which invokes QueryInterface with __uuidof(T::type). The resulting unique_com_ptr<T> is stored in the unique_ptr base.

Parameters
subjectOwning pointer to a generic IDispatch COM object. Ownership is transferred; the caller's handle is left null after construction.
Exceptions
std::invalid_argumentif subject is null.
std::runtime_errorif QueryInterface for T::type fails.

Definition at line 99 of file COMProxy.hpp.

References pacemaker::inca::detail::query_interface().

Here is the call graph for this function:

◆ COMProxy() [4/4]

template<class T >
COMProxy ( COMProxy< T > && )
default

Move ctor; transfers ownership of the COM pointer.

Member Function Documentation

◆ operator=()

template<class T >
COMProxy & operator= ( COMProxy< T > && )
default

Move assignment; transfers ownership of the COM pointer.


The documentation for this class was generated from the following file: