CComObjectRootEx::FinalConstruct
HRESULTFinalConstruct();
Return Value
One of the standard HRESULT values.
Remarks
Typically, override this method in the class derived from CComObjectRootEx to create any aggregated objects. For example:
class CMyAggObject : public CComObjectRootEx< ... >
{
DECLARE_GET_CONTROLLING_UNKNOWN
HRESULT FinalConstruct( )
{
return CoCreateInstance(CLSID_SomeServer,
GetControllingUnknown(), CLSCTX_ALL,
IID_ISomeServer, &m_pSomeServer);
}
...
};
If the construction fails, you can return an error. You can also use the macro DECLARE_PROTECT_FINAL_CONSTRUCT to protect your outer object from being deleted if (during creation) the internal aggregated object increments the reference count then decrements the count to 0.
By default, CComObjectRootEx::FinalConstruct simply returns S_OK.
Here is a typical way to create an aggregate:
Add an IUnknown pointer to your class object and initialize it to NULL in the constructor.
Override FinalConstruct to create the aggregate.
Use the IUnknown pointer you defined as the parameter to the COM_INTERFACE_ENTRY_AGGREGATE macro.
Override FinalRelease to release the IUnknown pointer.
CComObjectRootEx Overview | Class Members
See Also CComObjectRootEx::FinalRelease, DECLARE_GET_CONTROLLING_UNKNOWN