DLL Functions

[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.]

This topic describes how to implement a component as a dynamic-link library (DLL) in Microsoft DirectShow.

A DLL must implement the following functions so that it can be registered, unregistered, and loaded into memory.

  • DllMain: The DLL entry point. The name DllMain is a placeholder for the library-defined function name. The DirectShow implementation uses the name DllEntryPoint. For more information, see the Platform SDK.
  • DllGetClassObject: Creates a class factory instance. Described in the previous sections.
  • DllCanUnloadNow: Queries whether the DLL can safely be unloaded.
  • DllRegisterServer: Creates registry entries for the DLL.
  • DllUnregisterServer: Removes registry entries for the DLL.

Of these, the first three are implemented by DirectShow. If your factory template provides an initialization function in the m_lpfnInit member variable, that function is called from inside the DLL entry-point function. For more information on when the system calls the DLL entry-point function, see DllMain.

You must implement DllRegisterServer and DllUnregisterServer, but DirectShow provides a function named AMovieDllRegisterServer2 that does the necessary work. Your component can simply wrap this function, as shown in the following example:

STDAPI DllRegisterServer()
{
    return AMovieDllRegisterServer2( TRUE );
}

STDAPI DllUnregisterServer()
{
    return AMovieDllRegisterServer2( FALSE );
}

However, within DllRegisterServer and DllUnregisterServer you can customize the registration process as needed. If your DLL contains a filter, you might need to do some additional work. For more information, see How to Register DirectShow Filters.

In your module-definition (.def) file, export all the DLL functions except for the entry-point function. The following is an example .def file:

EXPORTS
    DllGetClassObject PRIVATE
    DllCanUnloadNow PRIVATE
    DllRegisterServer PRIVATE
    DllUnregisterServer PRIVATE

You can register the DLL using the Regsvr32.exe utility.

How to Create a DirectShow Filter DLL