共用方式為


CreateInstanceWithContext method

Creates Component Object Model (COM) objects that share a common context.

Syntax

HRESULT retVal = object.CreateInstanceWithContext(punkContext, punkOuter, riid, ppvObject);

Parameters

  • punkContext [in]
    Type: IUnknown

    A pointer to the IUnknown interface that specifies the context, or NULL to create the object in or with the default context.

  • punkOuter [in]
    Type: IUnknown

    If the object is created as part of an aggregate, a pointer to the controlling IUnknown interface of the aggregate. Otherwise,, punkOuter must be NULL.

  • riid [in]
    Type: REFIID

    A reference to the identifier of the interface to be used to communicate with the newly created object.

  • ppvObject [out]
    Type: void

    A pointer variable that receives the interface pointer requested by riid.

Remarks

The context can be used to cache objects that are created by the IClassFactory3 implementation for reuse, or to initialize objects as they are created. Passing NULL in punkContext indicates that the object is created with the default context.

When used with the Windows Internet Explorer scriptlet object library, the object pointer passed in punkContext must support the IServiceProvider interface. The client can specify the scriptlet context to use for creating objects by returning the object in response to the IServiceProvider::QueryService on the site for SID_SCRIPTLETCONTEXT.

Unlike IClassFactory, IClassFactory3 is not supported natively by the COM helper functions CoCreateInstance or DllGetClassObject.

See also

IClassFactory