Microsoft DirectX 8.0 |
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_Name | Name of the filter. |
m_ClsID | Pointer to the CLSID of the object. |
m_lpfnNew | Pointer to a function that creates an instance of the object. |
m_lpfnInit | Pointer to a function that gets called from the DLL entry point. |
m_pAMovieSetup_Filter | Pointer to an AMOVIESETUP_FILTER structure. |
Public Methods | |
IsClassID | Determines whether a CLSID matches this class template. |
CreateInstance | Calls the object-creation function for the class. |
Wide-character string containing the name of the filter.
Syntax
const WCHAR *m_Name;
Pointer to the CLSID of the object.
Syntax
const CLSID *m_ClsID;
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; }
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:
- bLoading: TRUE when the DLL is loaded, FALSE when the DLL is unloaded.
- rclsid: Pointer to the object's CLISD, specified in the m_ClsID member variable.
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.
Calls the object-creation function for the class.
Syntax
CUnknown *CreateInstance( LPUNKNOWN pUnk, HRESULT *phr );
Parameters
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.
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.