zoukankan      html  css  js  c++  java
  • 怎样给filter加入自己定义接口

    给一个filter加入接口,过程例如以下:

    1、建立一个声明接口的头文件“Interface.h” 。内容包含指定接口的GUID(使用GuidGen.exe)以及接口函数的声明。

        记得加 initguid.h 的include,不然使用时会出现"无法解析的外部符号_IID_"错误

    2、在Cfilter类的头文件filter.h开头加入  #include “Interface.h” 。

    3、在Cfilter类的声明中继承这个接口  CFilter:public Interface

    4、在Cfilter类的声明中添加Interface接口的函数的声明:

          //--------Interface methods----------
         STDMETHODIMP    SetServerAddr(char* inIP, int inPort);

    5在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加入到project里。2、使用前加入  #include “Interface.h”。3、在成功加入filter之后,使用QueryInterface函数获得接口指针就可以使用。

  • 相关阅读:
    WinCE 编译固定IP到内核
    wince telnet登陆密码的取消
    lab 美国大学实验室
    PLC 开放性源代码的软件
    linux 嵌入式Linux下3G无线上网卡的驱动
    创业者/职业经理人/员工受用的36句感悟
    iShoot Developer Makes $600,000 In One Month
    如何彻底解决Vista狂读硬盘的问题
    宁做创业狼,不做打工狗
    跟我学EJBCA系列一:安装
  • 原文地址:https://www.cnblogs.com/lytwajue/p/7227317.html
Copyright © 2011-2022 走看看