如何给filter添加自定义接口

时间:2023-03-09 01:29:33
如何给filter添加自定义接口

、在Cfilter类的定义中实现Interface接口的函数的定义:

//-----------------------Interface methods-----------------------------
    STDMETHODIMP CFilter::SetServerAddr(char* inIP, int inPort)
    {

……
         return S_OK;
    }

6、最后别忘了,在CFilter::NonDelegatingQueryInterface函数中添加两行代码,用来向外界暴露该接口:

// Basic COM - used here to reveal our own interfaces

STDMETHODIMP CFilter::NonDelegatingQueryInterface(REFIID riid, void ** ppv)

{
        ……

if (riid == IID_Interface)
                 return GetInterface((Interface *) this, ppv);
        …… 
    }

至此,filter的接口添加完毕。如果其它应用程序想要用这个接口,那么就像使用其它com组件一样。1、把Interface.h添加到工程里。2、使用前添加  #include “Interface.h”。3、在成功添加filter之后,使用QueryInterface函数获得接口指针即可使用。