pacemaker 3.0.3
COM automation for people with deadlines and a hatred of GUIs
 
Loading...
Searching...
No Matches
pacemaker::inca::detail Namespace Reference

Classes

struct  ComObjDeleter
 Custom deleter for COM objects. More...
 
class  COMProxy
 Owning smart-pointer base class for COM dispatch proxy objects. More...
 
struct  DispatchWrapper
 Helper struct for standardize interface retrieval. More...
 

Typedefs

template<class T >
using unique_com_ptr = std::unique_ptr<T, ComObjDeleter<T>>
 RAII owning pointer for COM objects.
 

Functions

template<class T >
auto query_interface (pacemaker::inca::detail::unique_com_ptr<::IDispatch > src) -> pacemaker::inca::detail::unique_com_ptr< T >
 Narrows a generic IDispatch pointer to a typed DispatchWrapper.
 

Typedef Documentation

◆ unique_com_ptr

template<class T >
using unique_com_ptr = std::unique_ptr<T, ComObjDeleter<T>>

RAII owning pointer for COM objects.

An alias for std::unique_ptr<T, ComObjDeleter<T>> that automatically calls T::Release() when the pointer goes out of scope. Ownership semantics are identical to std::unique_ptr: the type is move-only and non-copyable, ensuring that a COM object's reference count is never accidentally incremented by a copy

Typical usage

// rawPtr->Release() is called when p is destroyed.
std::unique_ptr< T, ComObjDeleter< T > > unique_com_ptr
RAII owning pointer for COM objects.
Template Parameters
TA COM interface type that exposes a Release() method.
See also
ComObjDeleter

Definition at line 55 of file unique_com_ptr.hpp.

Function Documentation

◆ query_interface()

template<class T >
auto query_interface ( pacemaker::inca::detail::unique_com_ptr<::IDispatch > src) -> pacemaker::inca::detail::unique_com_ptr<T>
nodiscard

Narrows a generic IDispatch pointer to a typed DispatchWrapper.

Calls QueryInterface on the supplied IDispatch using __uuidof(T::type), where T::type is the raw COM dispatch type that the DispatchWrapper T inherits from. On success the function returns an owning unique_com_ptr<T>; on failure it throws a standard exception so that COM errors surface immediately with context, rather that propagating as a null pointer that crashes later.

This function is called exclusively from COMProxy<T>'s owning ctor and is not part of the public API.

Template Parameters
TA DispatchWrapper struct that publicly inherits a COM dispatch type and declares using type = <raw dispatch type>. __uuidof(T::type) must be a valid expression.
Parameters
srcOwning pointer to the source IDispatch object. Ownership is consumed unconditionally: the pointer is released either because QueryInterface succeeded and the new typed pointer takes over, or because src goes out of scope on the exception path.
Returns
Owning unique_com_ptr<T> pointing to the same underlying COM object narrowed to the T interface.
Exceptions
std::invalid_argumentif src is null
std::runtime_errorif QueryInterface returns a failing HRESULT; the message includes the demangled name of T.
See also
pacemaker::inca::detail::COMProxy
pacemaker::inca::detail::unique_com_ptr

Definition at line 40 of file utils.hpp.

Referenced by COMProxy< T >::COMProxy().

Here is the caller graph for this function: