1.定义预处理命令_ATL_ATTRIBUTES

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:

VC++ 使用attributes定义接口的更多相关文章

  1. C#的接口基础教程之二 定义接口

    定义接口 从技术上讲,接口是一组包含了函数型方法的数据结构.通过这组数据结构,客户代码可以调用组件对象的功能. 定义接口的一般形式为: [attributes] [modifiers] interfa ...

  2. JAVA定义接口格式:

    [public]interface 接口名称 [extends父接口名列表] { //静态常量 [public] [static] [final] 数据类型变量名=常量值; //抽象方法 [publi ...

  3. Android中定义接口的方法

    1.接口方法用于回调(这里定义接口是为了使用其接口方法): public interface ICallback { public void func(); } public class Caller ...

  4. 怎样给filter加入自己定义接口及调用

    本样例是在VirtualCamera的基础上加入的自己定义接口用来实现exe控制osd的显示. 1. 接口部分 #ifndef __H_MyFilter__#define __H_MyFilter__ ...

  5. interface关键字定义接口

    package interface0; public interface InterfaceTest { /* * 接口的定义,使用interface关键字定义接口 */ public interfa ...

  6. Computer Science Theory for the Information Age-5: 学习理论——VC维的定义以及一些例子

    学习理论——VC维的定义以及一些例子 本文主要介绍一些学习理论上的东西.首先,我们得明确,从训练集上学习出来的分类器的最终目标是用于预测未知的样本,那么我们在训练的时候该用多少的样本才能使产生的分类器 ...

  7. “全栈2019”Java第六十章:如何定义接口

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  8. struts2 在拦截器进行注入(依据Action是否实现自己定义接口)

    比如:经常在Action中都须要获取当前登录的User,就须要获取Session.然后从Session获取当前登录的User,由于这些步骤都是反复操作,能够想办法在拦截器中进行实现.能够自己定义一个接 ...

  9. 用关键字interface定义接口,通过关键字implements来实现接口

    [定义]Java中,能够完成特定功能的,由若干属性和方法组织成的,相对独立的属性和方法的集合. [用途]实现类的多继承,以解决Java只能单继承,不支持多继承的问题. [特点] 用关键字interfa ...

随机推荐

  1. Android:Service

    Android Service: http://www.apkbus.com/android-15649-1-1.html android service 的各种用法(IPC.AIDL): http: ...

  2. Jquery属性选择器(同时匹配多个条件,与或非)(附样例)

    1. 前言 为了处理除了两项不符合条件外的选择,需要用到jquery选择器的多个条件匹配来处理,然后整理了一下相关的与或非的条件及其组合. 作为笔记记录. 2. 代码 <!DOCTYPE htm ...

  3. JS/Jquery版本的俄罗斯方块(附源码分析)

    转载于http://blog.csdn.net/unionline/article/details/63250597 且后续更新于此 1.前言 写这个jQuery版本的小游戏的缘由在于我想通过从零到有 ...

  4. lr使用linux Generator测试https莫名报 SSL protocol error when attempting to connect with host

    接收一个性能测试任务,各种原因需要使用linux agent产生压力.诡异的事发生了,同样脚本windows回放成功,使用linux agent报如下错误,脚本回放失败. Action.c(33): ...

  5. OCM_第十天课程:Section5—》数据仓库

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  6. 2017-2018-2 20155309南皓芯 Exp6 信息搜集与漏洞扫描

    实践内容 1.各种搜索技巧的应用 2.DNS IP注册信息的查询 3.基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具体服务的查点 4.漏洞扫描:会扫,会看报告,会查漏洞说明,会修补漏洞 基 ...

  7. java List.subList方法中的超级大陷阱

    ArrayList 中 subList 的基本用法: subList(fromIndex:int,toIndex:int):List<E> 返回从fromIndex到toindex-1 的 ...

  8. ERP商品管理业务逻辑封装(三十四)

    产品购进管理业务逻辑: public class ProductBLL { /// <summary> /// 产品对象添加 并且返回产品编号 /// </summary> / ...

  9. java利用Jsch实现在windows平台远程操作linux服务器

    说明:exec用于执行命令:sftp用于文件处理 package com.wyg.simple; import java.io.BufferedReader; import java.io.File; ...

  10. 白化(Whitening): PCA 与 ZCA (转)

    转自:findbill 本文讨论白化(Whitening),以及白化与 PCA(Principal Component Analysis) 和 ZCA(Zero-phase Component Ana ...