Microsoft Windows CE 3.0  

Instantiate the Filter

This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

All filters must add code to let the base classes instantiate the filter. To instantiate a filter, you must include two pieces of code in your filter: a static CreateInstancemember function in the derived filter class, and a means of informing the class factory in the base classes how to access this function.

Typically, the CreateInstancemember function calls the constructor for the derived filter class. The following examples show how to implement the CreateInstancemember function.

CUnknown *CGargle::CreateInstance(LPUNKNOWN punk,
HRESULT *phr) { CGargle *pNewObject = new CGargle(NAME("Gargle
Filter"), punk, phr); if (pNewObject == NULL) { *phr =
E_OUTOFMEMORY; } return pNewObject; } // CreateInstance

To communicate with the class factory, declare a global array of CFactoryTemplateobjects as g_Templatesand provide the name of your filter, the class identifier (CLSID) of your filter, and a pointer to the static CreateInstancemember function that creates your filter object.

// Needed for the CreateInstance mechanism
CFactoryTemplate g_Templates[2]= { { L"Gargle filter" ,
&CLSID_Gargle , Gargle::CreateInstance } , { L"Gargle filter
Property Page", &CLSID_GargProp,
GargleProperties::CreateInstance} }; int g_cTemplates =

You can add additional parameters to the CFactoryTemplatetemplates if you want your filter to be self-registering. For more information on this, see How to Register DirectShow Filters.

Finally, link your filter to Strmbase.lib and export DllGetClassObjectand DllCanUnloadNowusing a .def file.

 Last updated on Tuesday, May 18, 2004

© 2004 Microsoft Corporation. All rights reserved.