• MFC对COM的支持


    一.COM接口映射表

    BEGIN_INTERFACE_PART(Dictionary, IDictionary)
        INIT_INTERFACE_PART(CDictionary, Dictionary)
        STDMETHOD_(BOOL, Initialize)();
        STDMETHOD_(BOOL, LoadLibrary)(LPOLESTR);
        STDMETHOD_(BOOL, InsertWord)(LPOLESTR, LPOLESTR);
        STDMETHOD_(void, DeleteWord)( LPOLESTR);
        STDMETHOD_(BOOL, LookupWord)(LPOLESTR, LPOLESTR *);
        STDMETHOD_(BOOL, RestoreLibrary)(LPOLESTR);
        STDMETHOD_(void, FreeLibrary)();
    END_INTERFACE_PART_STATIC(Dictionary) 
    
    #define BEGIN_INTERFACE_PART(localClass, baseClass) \
        class X##localClass : public baseClass \
        { \
        public: \
            STDMETHOD_(ULONG, AddRef)(); \
            STDMETHOD_(ULONG, Release)(); \
            STDMETHOD(QueryInterface)(REFIID iid, LPVOID* ppvObj); \
    
    #ifndef _AFX_NO_NESTED_DERIVATION
    #define BEGIN_INTERFACE_PART_DERIVE(localClass, baseClass) \
        class X##localClass : public baseClass \
        { \
        public: \
    
    #else
    #define BEGIN_INTERFACE_PART_DERIVE(localClass, baseClass) \
        BEGIN_INTERFACE_PART(localClass, baseClass) \
    
    #endif
    
    #define END_INTERFACE_PART(localClass) \
        } m_x##localClass; \
        friend class X##localClass; \
    

    展开刚好是一个内部类,这样就省得写IUnknown的三个方法

    IUnknown的实现

    调用基类的三个方法就可以了

    /////////////////////////////////////////////////////////////////////////////
    // CDictionaryObj::XSpellCheck
    STDMETHODIMP_(ULONG) CDictionaryObj::XSpellCheck::AddRef()
    {
        METHOD_PROLOGUE_EX_(CDictionaryObj, SpellCheck)
        return (ULONG)pThis->ExternalAddRef();
    }
    
    STDMETHODIMP_(ULONG) CDictionaryObj::XSpellCheck::Release()
    {
        METHOD_PROLOGUE_EX_(CDictionaryObj, SpellCheck)
        return (ULONG)pThis->ExternalRelease();
    }
    
    STDMETHODIMP CDictionaryObj::XSpellCheck::QueryInterface(
        REFIID iid, LPVOID* ppvObj)
    {
        METHOD_PROLOGUE_EX_(CDictionaryObj, SpellCheck)
        return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
    }
    

    三.引出函数

    STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
    {
        AFX_MANAGE_STATE(AfxGetStaticModuleState());
        return AfxDllGetClassObject(rclsid, riid, ppv);
    }
    
    STDAPI DllCanUnloadNow(void)
    {
        AFX_MANAGE_STATE(AfxGetStaticModuleState());
        return AfxDllCanUnloadNow();
    }
    
    // by exporting DllRegisterServer, you can use regsvr.exe
    STDAPI DllRegisterServer(void)
    {
        AFX_MANAGE_STATE(AfxGetStaticModuleState());
        COleObjectFactory::UpdateRegistryAll();
        return S_OK;
    }
    
  • 相关阅读:
    glibc源码下载
    指令查找工具
    ubuntu下ldd,查看程序动态库信息
    gdb使用记录
    找到返回地址(1)
    vim自动格式化
    android 注入so
    Mac下安装m2crypto 解决找不到openssl头文件的错误
    Mac下android studio卡,居然这么解决了。。。。
    git忽略文件
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/2076840.html
Copyright © 2020-2023  润新知