CFactoryTemplate Class

CFactoryTemplate class hierarchy

The CFactoryTemplate class provides a template used by the default class factory code.

Create one CFactoryTemplate object in an array for every object class so that the default class factory code can create new instances.

This class holds the name of the object, the object's class identifier (CLSID), and a pointer to the creation function for the corresponding object. Initialize one of these in an array called g_Templates for each CLSID the application's dynamic-link library (DLL) supports. The creation function should take an LPUNKNOWN parameter and an HRESULT pointer and return an object derived from the CBaseObject class. Set the HRESULT to a failed value if there is any error in construction. An example declaration (from the Gargle sample filter) follows:

// list of class ids and creator functions for class factory

CFactoryTemplate g_Templates[2]= { { L"Gargle filter"         // CFactoryTemplate.m_name
                                   , &CLSID_Gargle            // CFactoryTemplate.m_ClsID 
                                   , CGargle::CreateInstance  // CFactoryTemplate.m_lpfnNew
								   , NULL                     // CFactoryTemplate.m_lpfnInit
								   , &sudGargle               // CFactoryTemplate.m_pAMovieSetup_Filter
                                   }
                                 , { L"Gargle filter property page"
                                   , &CLSID_GargProp
                                   , CGargleProperties::CreateInstance
                                   }
                                 };

int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);

Note that the name of the object is strictly necessary only if you are using the DllRegisterServer setup routine to implement self-registering of your filter. If you are not using this feature, you can set the first element of the g_Templates instance (m_Name) to NULL or L"".

Protected Data Members

m_ClsID Pointer to the CLSID of the object class.
m_lpfnNew Pointer to a function that creates an instance of the object class.
m_lpfnInit Pointer to a function that initializes a new instance of the object class.
m_Name Name of the filter; required when using filter self-registration services.
m_pAMovieSetup_Filter Pointer to an AMOVIESETUP_FILTER structure; required when using filter self-registration services.

Member Functions

CreateInstance Calls the object-creation function for the class.
IsClassID Determines whether a CLSID matches this class template.

CFactoryTemplate::CreateInstance

CFactoryTemplate Class

Calls the object-creation function for the class.

Syntax

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

Parameters

pUnk
Pointer to the IUnknown interface.
phr
Pointer to the HRESULT value into which to place resulting information.

Return Value

Returns an instance of the class object.

Remarks

The implementer of the class code registered using this factory template class is responsible for providing the code that creates an instance of the class object and assigning it to the m_lpfnNew data member. This member function simply calls that function and returns a new object of that type.

CFactoryTemplate::IsClassID

CFactoryTemplate Class

Determines if the class identifier (CLSID) passed matches the CLSID assigned to this class template.

Syntax

BOOL IsClassID(
  REFCLSID rclsid
  );

Parameters

rclsid
CLSID being tested.

Return Value

Returns TRUE if the CLSIDs are the same; otherwise, returns FALSE.


Top of Page Top of Page
© 2000 Microsoft and/or its suppliers. All rights reserved. Terms of Use.