MFC开发COM控件(1) ODL

来源:互联网 发布:flash for mac最新版 编辑:程序博客网 时间:2024/05/19 06:51

// COMs8MFCDual.odl : type library source for ActiveX Control project.
// 控件的类型库

// This file will be processed by the Make Type Library (mktyplib) tool to
// produce the type library (COMs8MFCDual.tlb) that will become a resource in
// COMs8MFCDual.ocx. 此文件将被MIDL处理以产生类型库文件,该类型库将作为一种资源存在
// 于.ocx控件中

//有关MIDL语言的信息请参考 《COM+开发人员参考库之第1卷第19章.TIF》

#include <olectl.h>    //ole2.0 control interface
#include <idispids.h> 
/*
可以使用C语言预处理指令#include,在你的IDL或ODL文件中包含头文件和其他文件。
但我们应该注意: 这一指令会在字面上包含指定文件的全部内容。
如果头文件包含在MIDL生成的存根文件中有不需要或者不想用的原形,或者包含非远程类型定义,
则应该使用MIDL的import指令代替#include指令
*/

//uuid 指定类型库、coclass或者接口的唯一标识
[ uuid(D3622FC9-19F5-400A-945A-018B0B07595D),  //标识了类型库
  version(1.0), //指定类型库的特定版本
  helpfile("COMs8MFCDual.hlp"), //为类型库设置Help文件的名称
  helpstring("COMs8MFCDual ActiveX Control module"), //将帮助串放入类型库
  control ] //将coclass或library看成COM控件,容器位置可以由
  //它得到附加类型库或者组件对象类
library COMS8MFCDUALLib  
//当MIDL遇到 library 关键字时,它将自动生成一个类型库,即通知MIDL编译器为接口和语句
//中引用到的类生成类型信息
/*
生成.tlb后,你可以单独发行,也可以作为一种资源包含在.exe/.ocx/.dll中,
大多数情况下,我们将其作为一种资源。
*/


{
/*
#define STDOLE_TLB "stdole2.tlb"
#ifdef _WIN64
#define STDTYPE_TLB "stdole2.tlb"
#else
#define STDTYPE_TLB "olepro32.dll"
#endif
*/
 importlib(STDOLE_TLB);
 /*
 STDOLE_TLB 是将windows操作系统下的/system32目录下的 stdole2.tlb 类型库导入
 */
 importlib(STDTYPE_TLB);
 /*
 STDTYPE_TLB
 */
/*
importlib 指令允许引用IDL或ODL文件中已编译的类型库。Importlib指令必须在library语句中,
而且必须在库中其他类型描述之前。导入库和生成的库一样,在应用程序运行时必须存在。
*/


/*
// {050B7561-65D0-405b-822D-B0708AE27CF5}
IMPLEMENT_OLECREATE(<<class>>, <<external_name>>,
0x50b7561, 0x65d0, 0x405b, 0x82, 0x2d, 0xb0, 0x70, 0x8a, 0xe2, 0x7c, 0xf5);
*/
   [ uuid(050B7561-65D0-405b-822D-B0708AE27CF5),
     helpstring("Double interface"), //helpstring 指定一个字符串,用来描述其将要应用的元素
     oleautomation, //指出接口是与自动化兼容的
     dual ] //识别通过IDispatch拥有属性和方法的接口,并直接通过vtable
    interface IInnerDual : IDispatch //继承自IDispatch,IInnerDual是一个自动化接口
    {
        [propput, id(1)] HRESULT Hello([in] BSTR newText);
  /*
  in关键字告诉MIDL: 需要将此参数值从客户传递给组件,存根代码不需要送回任何值
  */
        [propget, id(1)] HRESULT Hello([out, retval] BSTR* ret);
  /*
  out关键字告诉MIDL: 参数仅被用来从组件向客户传回有关的数据,
  代理不需要对输出参数进行列集,也不需要将参数传给组件
  */
        [id(2)] HRESULT SayHello(BSTR strHello);
  //propput 指定属性设置函数
  //propget 指定属性访问函数
    }
/*
 自动化技术直接以COM为基础,所有的自动化对象都实现了 IDispatch 接口,通过其暴露
 属性和方法,以便在客户程序中使用这些属性和方法。客户程序通过类型库(tlb)获得对象
 运行时刻的类型信息,其对对象属性和方法的引用实际上被转化为对 IDispatch::Invoke
 的调用。
*/

 //  Primary dispatch interface for CCOMs8MFCDualCtrl

 [ uuid(F5711E23-3746-451A-BDE8-C8D97B9BA31C),
   helpstring("Dispatch interface for COMs8MFCDual Control"), hidden ]
   /*保持与现有代码兼容的同时,从接口中删除成员*/
 dispinterface _DCOMs8MFCDual
 {
  properties:
   // NOTE - ClassWizard will maintain property information here.
   //    Use extreme caution when editing this section.
   //{{AFX_ODL_PROP(CCOMs8MFCDualCtrl)
   [id(1)] BSTR Hello;
   //}}AFX_ODL_PROP

  methods:
   // NOTE - ClassWizard will maintain method information here.
   //    Use extreme caution when editing this section.
   //{{AFX_ODL_METHOD(CCOMs8MFCDualCtrl)
   [id(2)] void SayHello(BSTR strHello);
   //}}AFX_ODL_METHOD

   [id(DISPID_ABOUTBOX)] void AboutBox();
 };

 //  Event dispatch interface for CCOMs8MFCDualCtrl

 [ uuid(187E757F-FAF6-462A-A2A1-B1AB20A1317E),
   helpstring("Event interface for COMs8MFCDual Control") ]
 dispinterface _DCOMs8MFCDualEvents
 {
  properties:
   //  Event interface has no properties

  methods:
   // NOTE - ClassWizard will maintain event information here.
   //    Use extreme caution when editing this section.
   //{{AFX_ODL_EVENT(CCOMs8MFCDualCtrl)
   //}}AFX_ODL_EVENT
 };

 //  Class information for CCOMs8MFCDualCtrl
 // 由于一个自动化对象可以支持多个自动化接口,所以我们使用 [default] 描述符
 // 以便显式指定缺省接口
 [ uuid(5D33FEBD-854F-4F25-ACBC-B551936A7FD7), //CLSID
   helpstring("COMs8MFCDual Control"), control ]
   //coclass 提供组件对象支持的接口列表
 coclass COMs8MFCDual  //定义了真正的自动化组件对象,该关键字用来定义一个组件
 { 
 // [default] dispinterface _DCOMs8MFCDual;
 // [default, source] dispinterface _DCOMs8MFCDualEvents;
        [default] interface IInnerDual;  //default 提供缺省接口
        [default, source] dispinterface _DCOMs8MFCDualEvents;
  //source 指定coclass、属性、方法的成员为事件源
        dispinterface _DCOMs8MFCDual;
  //dispinterface 定义一个属性和方法集,在此集合中可以调用
  //IDispatch::Invoke
 };


 //{{AFX_APPEND_ODL}}
 //}}AFX_APPEND_ODL}}
};