Tutorial step 3: building the DLL and testing the filter |
||
|
We have all that's necessary for a bare VirtualDub filter, and in fact, if this were an internal filter, all that would be left is to add the filterDef_tutorial structure to the list in f_list.cpp. However, for this filter to be loaded externally, we need to add the necessary DLL framework. Module load and unload functionsVirtualDub requires that filter DLLs export two functions:
Function VirtualdubFilterModuleInit2(fm: PFilterModule; const ff: PFilterFunctions; var vdfd_ver: Integer; var vdfd_compat: Integer): Integer; cdecl; These functions must be exported undecorated, that is, not as _VirtualdubFilterModuleInit@12 or some mess of C++ decorations. Note also at the functions start with Virtualdub, with the second d uncapitalized. The purpose of the init routines is to add/remove filters from VirtualDub's global list when the DLL loads and unloads, and to perform any necessary module-level initialization. Preferably, module-level initialization should be kept to a minimum to reduce resource usage when the module's filters are loaded but unused. Usually, the init/deinit functions need only call ff->addFilter() and ff->removeFilter(). The init function returns non-zero on failure, but VirtualDub does not remove any filters you have already added. With multiple filters, you must back out any filters you have already added if you wish to fail because not all filters could be loaded. Init functions also have one other purpose: they allow VirtualDub to detect if a filter uses an old, incompatible interface. The vdfd_ver variable holds the current interface version, and the vdfd_compat holds the earliest version that this build of VirtualDub is backwards compatible with. Before returning, set them with the versions in your header files:
vdfd_ver := VIRTUALDUB_FILTERDEF_VERSION; If your filter uses an interface version which the current version of VirtualDub cannot support, VirtualDub will abort the filter load and notify the user.
Creating the load and unload functions for the tutorial filterBecause tutorial only has one filter in its module, the functions are fairly straightforward:
Var Because the FilterDefinition record may expand later, VirtualDub returns a new definition pointer when the filter is added. This pointer is the record that VirtualDub uses, and is the one that needs to be passed to the removeFilter function. Building and testing the filter
Create a new Win32 DLL project if you haven't already, and throw all the code so far into a file
along with uses VdFilter;. Compile and build a DLL file out of it. If you used the directive {$E .vdf},
the output file will already have the ".vdf" extension. Otherwise rename the output DLL to tutorial.vdf. Right
now your delphi project file should look like this. |
||
© 2005 Fernando Reis < >Adapted from VirtualDub external filter SDK 1.05 documentation © 1999-2001 Avery Lee |