IClassFactory::CreateInstance
Creates an
uninitialized object.
HRESULT CreateInstance(
IUnknown *
pUnkOuter, |
//Pointer to whether object is or isn t part of an
aggregate |
REFIID riid, |
//Reference to the identifier of the interface |
void ** ppvObject |
//Indirect pointer to the interface |
); |
|
Parameters
pUnkOuter
[in] If the
object is being created as part of an aggregate, pointer to the controlling IUnknown
interface of the aggregate. Otherwise, pUnkOuter must be NULL.
riid
[in]
Reference to the identifier of the interface to be used to communicate with the
newly created object. If pUnkOuter is NULL, this parameter is frequently
the IID of the initializing interface; if pUnkOuter is non-NULL, riid
must be IID_IUnknown (defined in the header as the IID for IUnknown).
ppvObject
[out]
Indirect pointer to the requested interface. If the object does not support the
interface specified in riid, ppvObject must be set to NULL.
Return Values
This method
supports the standard return values E_UNEXPECTED, E_OUTOFMEMORY, and
E_INVALIDARG, as well as the following:
S_OK
The specified
object was created.
CLASS_E_NOAGGREGATION
The pUnkOuter
parameter was non-NULL and the object does not support aggregation.
E_NOINTERFACE
The object
that ppvObject points to does not support the interface identified by riid.
Remarks
The IClassFactory
The pUnkOuter
parameter indicates whether the object is being created as part of an
aggregate. Object definitions are not required to support aggregation they must be specifically designed and implemented to
support it.
The riid
parameter specifies the IID (interface identifier) of the interface through
which you will communicate with the new object. If pUnkOuter is non-NULL
(indicating aggregation), the value of the riid parameter must be IID_IUnknown.
If the object is not part of an aggregate, riid often specifies the
interface though which the object will be initialized.
For OLE
embeddings, the initialization interface is IPersistStorage
In general,
if an application supports only one class of objects, and the class object is
registered for single use, only one object can be created. The application must
not create other objects, and a request to do so should return an error from IClassFactory::CreateInstance.
The same is true for applications that support multiple classes, each with a
class object registered for single use; a CreateInstance for one class
followed by a CreateInstance for any of the classes should return an
error.
To avoid
returning an error, applications that support multiple classes with single-use
class objects can revoke the registered class object of the first class by
calling CoRevokeClassObject
See Also