惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
博客园 - Franky
L
LangChain Blog
GbyAI
GbyAI
A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 叶小钗
N
Netflix TechBlog - Medium
D
DataBreaches.Net
Martin Fowler
Martin Fowler
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
爱范儿
爱范儿
罗磊的独立博客
H
Help Net Security
云风的 BLOG
云风的 BLOG
C
Check Point Blog

博客园 - Clingingboy

冒个泡,刷刷存在感 使用文件映射和信号量来进程间通信 Xperf Basics: Recording a Trace (the easy way)(转) Xperf Basics: Recording a Trace(转) Xperf Analysis Basics(转) Android相关sdk使用 Uniscribe文字自动换行 Chrome RenderText分析(2) c++智能指针 codepage IMLangCodePages GUI 快捷键的实现思路 Menu实现逻辑 控件保持多种绘图状态的做法 2个函数宏技巧 绘图 Painter转接口封装的方式 DirectUI消息循环的简单封装 c++以代理的方式来实现接口化编程 c++对象工厂 使用模板来解决接口继承问题
VC++ 使用attributes定义接口
Clingingboy · 2013-11-04 · via 博客园 - Clingingboy

2013-11-04 19:26  Clingingboy  阅读(921)  评论()    收藏  举报

1.定义预处理命令_ATL_ATTRIBUTES

image

2.在一个全局的Cpp文件里面配置module的attribute

[module(dll, uuid = "{3845951F-15B8-4286-8E7D-E9D4F5C7B6CE}", 
    name = "TestApp")]

3.定义接口

[
    object,
    uuid("9F414A8A-1D5E-4aff-A60E-CFD65155ABB6"),
    dual, helpstring("IGFCursorMgr Interface"),
    pointer_default(unique)
]
__interface IEmployee : IDispatch
{
    HRESULT DoWork(BSTR bstrTask);
};

[
    coclass,
    default(IEmployee),
    threading(free),
    vi_progid("TXGF.CGFCoCursorMgr"),
    progid("TXGF.CGFCoCursorMgr.1"),
    version(1.0),
    uuid("20BB9542-E499-4618-9E2D-079A06FD99B1"),
    helpstring("CGFCoCursorMgr Class")
]
class ATL_NO_VTABLE CManager:public IEmployee
{
public:

    CManager()
    {
        //InternalAddRef();
    }

    DECLARE_PROTECT_FINAL_CONSTRUCT()

    HRESULT FinalConstruct()
    {
        return S_OK;
    }

    void FinalRelease()
    {}

    HRESULT DoWork(BSTR bstrTask)
    {
        CComObject<CManager> * pObj = NULL;
        CComObject<CManager>::CreateInstance(&pObj);
        return S_OK;
    }
};

4.引用ATL命名空间

如遇编译错误error C3358: 'IDispatchImpl': symbol not found

需要添加ATL的命名空间using namespace ATL;

关于使用的参考资料:http://msdn.microsoft.com/en-us/magazine/cc301337.aspx

      The generated code in Figure 6 shows that the [coclass] attribute makes the compiler derive a class from CComObjectRootEx<> and this provides QueryInterface through the interface map. The compiler generates this map by looking at the interfaces that the class is derived from. If you want to add your own entries to this map, you can use the [com_interface_entry()] attribute. The parameter to this attribute is the COM_INTERFACE_ENTRY macro that you want to add to the top of the map. For example: