IClassFactory::CreateInstance

HRESULT IClassFactory::CreateInstance(pUnkOuter, iid, ppvObject)

Create an uninitialized instance, that is, object, of the class associated with the class factory, returning an interface pointer of type iid on the object to the caller in the out-parameter ppvObject.

If the object is being created as part of an aggregate—that is, the client of the object in this case is also an object server itself—then pUnkOuter contains the IUnknown pointer to the "outer unknown." See "Object Reusability" in Chapter 6 for more information. Class implementations need to be consciously designed to be aggregatable and accordingly not all classes are so designed.

Argument

Type

Description

pUnkOuter

IUnknown *

The controlling unknown of the aggregate object if this object is being created as part of an aggregate. If NULL, then the object is not being aggregated, which is the case when the object is being created from a pure client. If non-NULL and the class does not support aggregation, then the function returns CLASS_E_NOAGGREGATION.

iid

REFIID

The identifier of the first interface desired by the caller through which it will communicate with the object; usually the "initialization interface."

ppv

void **

The place in which the first interface pointer is to be returned.


Return Value

Meaning

S_OK

Success. A new instance was created.

E_NOAGGREGATION

Use of aggregation was requested, but this class does not support it.

E_OUTOFMEMORY

Memory could not be allocated to service the request.

E_UNEXPECTED

An unknown error occurred.