To add an interface to a filter, follow these steps:
1. Create an interface header file "interface. H", which contains the guid(use guidgen.exe) of the interface and the declaration of the interface function.
Remember to add the include of initguid. H. Otherwise, the "unresolvable external symbol _ IID _" error will occur during use.
2. Add # include "interface. h" at the beginning of the header file filter. H of the cfilter class ".
3. inherit the cfilter: public interface from the cfilter class declaration.
4. Add the interface function declaration in the cfilter class declaration:
// -------- Interface methods ----------
Stdmethodimp setserveraddr (char * inip, int inport );
5. Define the functions that implement the interface in the definition of the cfilter class:
// ----------------------- Interface methods -----------------------------
Stdmethodimp cfilter: setserveraddr (char * inip, int inport)
{
......
Return s_ OK;
}
6. Do not forget to add two lines of code to the cfilter: nondelegatingqueryinterface function to expose the interface to the outside world:
// Basic com-used here to reveal our own interfaces
Stdmethodimp cfilter: nondelegatingqueryinterface (refiid riid, void ** GMM)
{
......
If (riid = iid_interface)
Return getinterface (interface *) This, GMM );
......
}
So far, the filter interface has been added. If other applications want to use this interface, it is like using other COM components. 1. Add interface. H to the project. 2. Add # include "interface. h" before use ". 3. After the filter is successfully added, use the QueryInterface function to obtain the interface pointer.
How to add custom interfaces to Filters