CComPtrBase::CoCreateInstance

Call this method to create an object of the class associated with a specified Class ID or Program ID.

HRESULT CoCreateInstance(
   LPCOLESTR szProgID,
   LPUNKNOWN pUnkOuter = NULL,
   DWORD dwClsContext = CLSCTX_ALL 
) throw( );
HRESULT CoCreateInstance(
   REFCLSID rclsid,
   LPUNKNOWN pUnkOuter = NULL,
   DWORD dwClsContext = CLSCTX_ALL 
) throw( );

Parameters

  • szProgID
    Pointer to a ProgID, used to recover the CLSID.

  • pUnkOuter
    If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, is a pointer to the aggregate object's IUnknown interface (the controlling IUnknown).

  • dwClsContext
    Context in which the code that manages the newly created object will run.

  • rclsid
    CLSID associated with the data and code that will be used to create the object.

Return Value

Returns S_OK on success, or REGDB_E_CLASSNOTREG, CLASS_E_NOAGGREGATION, or E_NOINTERFACE on failure. See CoCreateClassInstance for a description of these errors.

Remarks

If the first form of the method is called, CLSIDFromProgID is used to recover the CLSID. Both forms then call CoCreateClassInstance.

In debug builds, an assertion error will occur if CComPtrBase::p is not equal to NULL.

Requirements

Header: atlcomcli.h

See Also

Concepts

CComPtrBase Class

CComPtrBase Members