title | ms.custom | ms.date | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CComObject Class | Microsoft Docs |
11/04/2016 |
|
reference |
|
|
|
e2b6433b-6349-4749-b4bc-acbd7a22c8b0 |
19 |
mikeblome |
mblome |
ghogen |
This class implements IUnknown for a nonaggregated object.
template<class Base>
class CComObject : public Base
Base
Your class, derived from CComObjectRoot or CComObjectRootEx, as well as from any other interfaces you want to support on the object.
Name | Description |
---|---|
CComObject::CComObject | The constructor. |
CComObject::~CComObject | The destructor. |
Name | Description |
---|---|
CComObject::AddRef | Increments the reference count on the object. |
CComObject::CreateInstance | (Static) Creates a new CComObject object. |
CComObject::QueryInterface | Retrieves a pointer to the requested interface. |
CComObject::Release | Decrements the reference count on the object. |
CComObject
implements IUnknown for a nonaggregated object. However, calls to QueryInterface
, AddRef
, and Release are delegated to CComObjectRootEx
.
For more information about using CComObject
, see the article Fundamentals of ATL COM Objects.
Base
CComObject
Header: atlcom.h
Increments the reference count on the object.
STDMETHOD_(ULONG, AddRef)();
This function returns the new incremented reference count on the object. This value may be useful for diagnostics or testing.
The constructor increments the module lock count.
CComObject(void* = NULL);
void*
[in] This unnamed parameter is not used. It exists for symmetry with other CComXXXObject
XXX constructors.
The destructor decrements it.
If a CComObject
-derived object is successfully constructed using the new operator, the initial reference count is 0. To set the reference count to the proper value (1), make a call to the AddRef function.
The destructor.
CComObject();
Frees all allocated resources, calls FinalRelease, and decrements the module lock count.
This static function allows you to create a new CComObject<Base
> object, without the overhead of CoCreateInstance.
static HRESULT WINAPI CreateInstance(CComObject<Base>** pp);
pp
[out] A pointer to a CComObject<Base
> pointer. If CreateInstance
is unsuccessful, pp
is set to NULL.
A standard HRESULT
value.
The object returned has a reference count of zero, so call AddRef
immediately, then use Release to free the reference on the object pointer when you're done.
If you do not need direct access to the object, but still want to create a new object without the overhead of CoCreateInstance
, use CComCoClass::CreateInstance instead.
[!code-cppNVC_ATL_COM#38]
[!code-cppNVC_ATL_COM#39]
Retrieves a pointer to the requested interface.
STDMETHOD(QueryInterface)(REFIID iid, void** ppvObject);
template <class Q>
HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp);
iid
[in] The identifier of the interface being requested.
ppvObject
[out] A pointer to the interface pointer identified by iid
. If the object does not support this interface, ppvObject
is set to NULL.
pp
[out] A pointer to the interface pointer identified by type Q
. If the object does not support this interface, pp
is set to NULL.
A standard HRESULT
value.
Decrements the reference count on the object.
STDMETHOD_(ULONG, Release)();
This function returns the new decremented reference count on the object. In debug builds, the return value may be useful for diagnostics or testing. In non-debug builds, Release always returns 0.
CComAggObject Class
CComPolyObject Class
DECLARE_AGGREGATABLE
DECLARE_NOT_AGGREGATABLE
Class Overview