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

推荐订阅源

Last Week in AI
Last Week in AI
Project Zero
Project Zero
L
LINUX DO - 最新话题
C
Cisco Blogs
P
Privacy International News Feed
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security @ Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
Webroot Blog
Webroot Blog
K
Kaspersky official blog
Help Net Security
Help Net Security
博客园_首页
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
雷峰网
雷峰网
The Last Watchdog
The Last Watchdog
WordPress大学
WordPress大学
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
A
Arctic Wolf
I
Intezer
V
V2EX
博客园 - 【当耐特】
Latest news
Latest news
T
Tenable Blog
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
Cyberwarzone
Cyberwarzone
量子位
G
GRAHAM CLULEY
T
Troy Hunt's Blog
博客园 - Franky
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 三生石上(FineUI控件)
TaoSecurity Blog
TaoSecurity Blog
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
Jina AI
Jina AI
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Scott Helme
Scott Helme

博客园 - 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: