다음을 통해 공유


Instantiate the Filter (Windows CE 5.0)

Send Feedback

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 CreateInstance member function in the derived filter class
  • A means of informing the class factory in the base classes how to access this function

Typically, the CreateInstance member function calls the constructor for the derived filter class.

The following examples show how to implement the CreateInstance member 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 CFactoryTemplate objects as g_Templates and provide the name of your filter, the class identifier (CLSID) of your filter, and a pointer to the static CreateInstance member 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 = sizeof(g_Templates)/sizeof(g_Templates[0]);

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

Finally, link your filter to Strmbase.lib and export DllGetClassObject and DllCanUnloadNow using a .def file.

See Also

Write a Transform Filter

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.