TSDuck v3.40-4033
MPEG Transport Stream Toolkit
|
Managed pointers for COM objects, auto-released (Windows-specific). More...
#include <tsComPtr.h>
Public Member Functions | |
ComPtr (::IUnknown *obj, const IID &interface_id, Report &report=(ts::CerrReport::Instance())) | |
Constructor using IUnknown::QueryInterface(). | |
ComPtr (COMCLASS *p=0, ::HRESULT hr=S_OK) | |
Default constructor. | |
ComPtr (ComPtr< COMCLASS > &&p) | |
Move constructor. | |
ComPtr (const ::IID &class_id, const ::IID &interface_id, Report &report=(ts::CerrReport::Instance())) | |
Constructor using CoCreateInstance(). | |
ComPtr (const ComPtr< COMCLASS > &p) | |
Copy constructor. | |
~ComPtr () | |
Destructor. | |
template<class COMSUBCLASS > requires std::derived_from<COMSUBCLASS, COMCLASS> | |
ComPtr< COMCLASS > & | assign (const ComPtr< COMSUBCLASS > &p) |
Assignment from a ComPtr to a subclass. | |
ComPtr< COMCLASS > & | bindToObject (::IMoniker *moniker, const IID &interface_id, Report &report=(ts::CerrReport::Instance())) |
Assign using IMoniker::BindToObject If the COM interface is successfully retrieved, it becomes managed and its reference count is unchanged (== 1). | |
UString | className () const |
Get the "class name" (formatted GUID) of this object. | |
ComPtr< COMCLASS > & | createInstance (const ::IID &class_id, const ::IID &interface_id, Report &report=(ts::CerrReport::Instance())) |
Assign using CoCreateInstance(). | |
COMCLASS ** | creator () |
Release previous pointer, return a receiver for new pointer. | |
bool | expose (const ::IID &iid) const |
Check if the object exposes an interface. | |
bool | isNull () const |
Check if null pointer. | |
COMCLASS & | operator* () const |
Dereference operator. | |
COMCLASS * | operator-> () const |
Dereference operator. | |
ComPtr< COMCLASS > & | operator= (COMCLASS *p) |
Assignment operator from a COM object pointer. | |
ComPtr< COMCLASS > & | operator= (ComPtr< COMCLASS > &&p) |
Move assignment operator. | |
ComPtr< COMCLASS > & | operator= (const ComPtr< COMCLASS > &p) |
Assignment operator. | |
COMCLASS * | pointer () const |
To access a COM object pointer, without releasing it. | |
ComPtr< COMCLASS > & | queryInterface (::IUnknown *obj, const IID &interface_id, Report &report=(ts::CerrReport::Instance())) |
Assign using IUnknown::QueryInterface If the COM interface is successfully retrieved, it becomes managed and its reference count is unchanged (== 1). | |
int | refCount () const |
Get the reference count to the object. | |
void | release () |
Release the COM object, its reference count is decremented. | |
Managed pointers for COM objects, auto-released (Windows-specific).
COMCLASS | A COM interface or object class. |
If TS_COM_INSTRUMENTATION
is defined and the application is compiled in debug mode, the ComPtr class produces abundant trace messages on the standard error.
Trace line format:
With:
ts::ComPtr< COMCLASS >::ComPtr | ( | COMCLASS * | p = 0 , |
::HRESULT | hr = S_OK |
||
) |
ts::ComPtr< COMCLASS >::ComPtr | ( | const ComPtr< COMCLASS > & | p | ) |
ts::ComPtr< COMCLASS >::ComPtr | ( | ComPtr< COMCLASS > && | p | ) |
ts::ComPtr< COMCLASS >::ComPtr | ( | const ::IID & | class_id, |
const ::IID & | interface_id, | ||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Constructor using CoCreateInstance().
If the COM object is successfully created, it becomes managed and its reference count is unchanged (== 1).
[in] | class_id | Class id of the COM object to create. |
[in] | interface_id | Id of the interface we request in the object. |
[in] | report | Where to report errors. |
Example:
ts::ComPtr< COMCLASS >::ComPtr | ( | ::IUnknown * | obj, |
const IID & | interface_id, | ||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
ts::ComPtr< COMCLASS >::~ComPtr | ( | ) |
Destructor.
The COM object is released (its reference count is decremented).
bool ts::ComPtr< COMCLASS >::isNull | ( | ) | const |
Check if null pointer.
COMCLASS * ts::ComPtr< COMCLASS >::pointer | ( | ) | const |
COMCLASS & ts::ComPtr< COMCLASS >::operator* | ( | ) | const |
COMCLASS * ts::ComPtr< COMCLASS >::operator-> | ( | ) | const |
COMCLASS ** ts::ComPtr< COMCLASS >::creator | ( | ) |
void ts::ComPtr< COMCLASS >::release | ( | ) |
Release the COM object, its reference count is decremented.
The pointer becomes null.
int ts::ComPtr< COMCLASS >::refCount | ( | ) | const |
Get the reference count to the object.
WARNING: This should be used for test or debug purpose only. Since there is no direct way to get the reference count of a COM object, we perform an AddRef / Release operation. The reference count is returned by Release().
ComPtr< COMCLASS > & ts::ComPtr< COMCLASS >::assign | ( | const ComPtr< COMSUBCLASS > & | p | ) |
ComPtr< COMCLASS > & ts::ComPtr< COMCLASS >::operator= | ( | const ComPtr< COMCLASS > & | p | ) |
ComPtr< COMCLASS > & ts::ComPtr< COMCLASS >::operator= | ( | ComPtr< COMCLASS > && | p | ) |
ComPtr< COMCLASS > & ts::ComPtr< COMCLASS >::operator= | ( | COMCLASS * | p | ) |
ComPtr< COMCLASS > & ts::ComPtr< COMCLASS >::createInstance | ( | const ::IID & | class_id, |
const ::IID & | interface_id, | ||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Assign using CoCreateInstance().
If the COM object is successfully created, it becomes managed and its reference count is unchanged (== 1).
[in] | class_id | Class id of the COM object to create. |
[in] | interface_id | Id of the interface we request in the object. |
[in] | report | Where to report errors. |
ComPtr< COMCLASS > & ts::ComPtr< COMCLASS >::queryInterface | ( | ::IUnknown * | obj, |
const IID & | interface_id, | ||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Assign using IUnknown::QueryInterface If the COM interface is successfully retrieved, it becomes managed and its reference count is unchanged (== 1).
[in] | obj | A COM object. |
[in] | interface_id | Id of the interface we request in the object. |
[in] | report | Where to report errors. |
ComPtr< COMCLASS > & ts::ComPtr< COMCLASS >::bindToObject | ( | ::IMoniker * | moniker, |
const IID & | interface_id, | ||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Assign using IMoniker::BindToObject If the COM interface is successfully retrieved, it becomes managed and its reference count is unchanged (== 1).
[in] | moniker | The moniker to use. |
[in] | interface_id | Id of the interface we request in the object. |
[in] | report | Where to report errors. |
bool ts::ComPtr< COMCLASS >::expose | ( | const ::IID & | iid | ) | const |
Check if the object exposes an interface.
[in] | iid | Id of the interface we request in the object. |
UString ts::ComPtr< COMCLASS >::className | ( | ) | const |
Get the "class name" (formatted GUID) of this object.
Warning: Very slow, eat CPU time, use with care.