Microsoft DirectX 8.0

CFactoryTemplate Class

Provides a template for creating class factories.

Declaration: Combase.h

In Microsoft® DirectShow®, class factories are specialized using the CFactoryTemplate class, also called the factory template. Each class factory holds a pointer to a factory template. The factory template contains information about a COM object, including the object's class identifier (CLSID) and a pointer to a function that creates the object.

In your DLL, declare a global array of factory templates named g_Templates. Include one factory template for each object in the DLL. When the DllGetClassObject function makes a new class factory, it searches the array for a template with a matching CLSID. Assuming it finds one, it creates a class factory that holds a pointer to the matching template. When the client calls IClassFactory::CreateInstance, the class factory calls the instantiation function defined in the template.

For more information, see How to Create a DLL.

Public Member Variables
m_NameName of the filter.
m_ClsIDPointer to the CLSID of the object.
m_lpfnNewPointer to a function that creates an instance of the object.
m_lpfnInitPointer to a function that gets called from the DLL entry point.
m_pAMovieSetup_FilterPointer to an AMOVIESETUP_FILTER structure.
Public Methods
IsClassIDDetermines whether a CLSID matches this class template.
CreateInstanceCalls the object-creation function for the class.

CFactoryTemplate.m_Name

CFactoryTemplate Class

Wide-character string containing the name of the filter.

Syntax

const WCHAR *m_Name;

CFactoryTemplate.m_ClsID

CFactoryTemplate Class

Pointer to the CLSID of the object.

Syntax

const CLSID *m_ClsID;

CFactoryTemplate.m_lpfnNew

CFactoryTemplate Class

Pointer to a function that creates an instance of the object.

Syntax

typedef CUnknown *(CALLBACK *LPFNNewCOMObject)(LPUNKNOWN pUnkOuter, HRESULT *phr);

LPFNNewCOMObject m_lpfnNew;

Remarks

In your DLL, declare a static function that returns a pointer to a new instance of the object. In the factory template, set the m_lpfnNew member variable to the address of this static function.

The following example shows a typical function for m_lpfnNew:

CUnknown * WINAPI CMyComponent::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr) 
{
    CMyComponent *pNewObject = new CMyComponent(NAME("My Component"), pUnk, pHr );
    if (pNewObject == NULL) 
{
        *phr = E_OUTOFMEMORY;
    }
    return pNewObject;
} 

CFactoryTemplate.m_lpfnInit

CFactoryTemplate Class

Pointer to a function that gets called from the DLL entry point. Can be NULL.

Syntax

typedef void (CALLBACK *LPFNInitRoutine)(BOOL bLoading, const CLSID *rclsid);

LPFNInitRoutine m_lpfnInit;

Remarks

If you provide this function in your DLL, the DLL entry-point function calls it with following parameters:

CFactoryTemplate.m_pAMovieSetup_Filter

CFactoryTemplate Class

Pointer to an AMOVIESETUP_FILTER structure.

Syntax

const AMOVIESETUP_FILTER *m_pAMovieSetup_Filter;

Remarks

Use this structure to make a filter self-registering. If your component is not a filter, this member variable can be NULL. For more information, see How to Register DirectShow Filters.

CFactoryTemplate::CreateInstance

CFactoryTemplate Class

Calls the object-creation function for the class.

Syntax

CUnknown *CreateInstance(
    LPUNKNOWN pUnk,
    HRESULT *phr
);

Parameters

pUnk
Pointer to the aggregating IUnknown interface.
phr
Pointer to a variable that receives an HRESULT value indicating the success or failure of the method.

Return Value

Returns an instance of the class object.

Remarks

The IClassFactory::CreateInstance method calls this class method. This method calls the function pointed to by the m_lpfnNew member variable.

CFactoryTemplate::IsClassID

CFactoryTemplate Class

Determines whether a CLSID matches this class template.

Syntax

BOOL IsClassID(
    REFCLSID rclsid
);

Parameters

rclsid
Reference to a CLSID.

Return Value

Returns TRUE if the rclsid parameter is the same CLSID as the m_ClsID member variable, or else returns FALSE.