Step 10. Support COM Registration

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The last remaining task is to support COM registration, so that the property frame can create new instances of your property page. Add another CFactoryTemplate entry to the global g_Templates array, which is used to register all of the COM objects in your DLL. Do not include any filter set-up information for the property page.

const AMOVIESETUP_FILTER FilterSetupData = 
{ 
    /* Not shown ... */
};

CFactoryTemplate g_Templates[] =
{   
    // This entry is for the filter.
    {
        wszName,
        &CLSID_GrayFilter,
        CGrayFilter::CreateInstance,
        NULL,
        &FilterSetupData 
    },
    // This entry is for the property page.
    { 
        L"Saturation Props",
        &CLSID_SaturationProp,
        CGrayProp::CreateInstance, 
        NULL, NULL
    }
};

If you declare g_cTemplates as shown in the following code, then it automatically has the correct value based on the array size:

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

Also, add a static CreateInstance method to the property page class. You can name the method anything that you prefer, but the signature must match the one shown the following example:

static CUnknown * WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr) 
{
    CGrayProp *pNewObject = new CGrayProp(pUnk);
    if (pNewObject == NULL) 
    {
        *pHr = E_OUTOFMEMORY;
    }
    return pNewObject;
} 

To test the property page, register the DLL and then load the filter in GraphEdit. Right-click the filter and select Filter Properties.

Creating a Filter Property Page

How to Create a DirectShow Filter DLL