g_Templates的类型定义:
class CFactoryTemplate {
public:
const WCHAR * m_Name;
const CLSID * m_ClsID;
LPFNNewCOMObject m_lpfnNew;
LPFNInitRoutine m_lpfnInit; //用于DLL加载时初始化的,一般不用
const AMOVIESETUP_FILTER * m_pAMovieSetup_Filter;
BOOL IsClassID(REFCLSID rclsid) const {
return (IsEqualCLSID(*m_ClsID,rclsid));
};
CUnknown *CreateInstance(LPUNKNOWN pUnk, HRESULT *phr) const {
CheckPointer(phr,NULL);
return m_lpfnNew(pUnk, phr);
};
};
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
当调用DllGetClassObject来创建对应CLSID的类工厂时,会引用g_cTemplates 以及g_Templates以创建对应于表格里的每个元素的类工厂CClassFactory,返回类厂接口指针,利用该指针调用m_pTemplate->CreateInstance(pUnkOuter, &hr);以创建自己的filter.