COM组件双接口对象模型
模型如下:


这里COM对象一共实现了三个接口,IUnknown,IDispatch, Ixxx. 每个COM都必须实现IUnknown,不考虑在内的话共实现了IDispatch和自定义接口Ixxx两个,故称双接口对象。
IDispatch主要是给解释型语言脚本用的,因为脚本没办法直接调用多态的接口函数。
#include <iostream>
using namespace std; class IUnknown
{
public:
virtual long QueryInterface( long riid, void * * ppvObject) = ;
virtual long AddRef( void) = ;
virtual long Release( void) = ;
}; class IDispatch : public IUnknown
{
public:
virtual void GetTypeInfoCount() = ;
virtual void GetTypeInfo() = ;
virtual void GetIDsOfNames() = ;
virtual void Invoke() = ;
}; class IMyDualTest : public IDispatch
{
public:
virtual long Add(long n1, long n2, long* pVal) = ;
}; class CMyDualTest: public IMyDualTest
{
public:
CMyDualTest():a(){}
// IUnknown
long QueryInterface( long riid, void * * ppvObject) { cout<<"QueryInterface"<<endl; return ;}
long AddRef( void) { cout<<"AddRef"<<endl; return ;}
long Release( void) { cout<<"Release"<<endl; return ;} // IDispatch
virtual void GetTypeInfoCount(){ cout<<"GetTypeInfoCount"<<endl;}
virtual void GetTypeInfo() { cout<<"GetTypeInfo"<<endl;}
virtual void GetIDsOfNames() { cout<<"GetIDsOfNames"<<endl;}
virtual void Invoke() { cout<<"Invoke"<<endl;} // IMyDualTest
long Add(long n1, long n2, long* pVal) { cout<<"Add"<<endl; return ;} private:
int a;
}; //typedef long (*QueryInterfaceType)( long riid, void * * ppvObject);
typedef long (*AddRefType)( void);
//typedef long (*ReleaseType)( void);
//
//typedef long (CMyTest::*QueryInterfaceClassType)( long riid, void * * ppvObject); void main()
{
CMyDualTest * pTest = new CMyDualTest; int * pFirst = (int*)(*(int*)pTest); for(int i=; i<; i++)
{
((AddRefType)(*(pFirst+i)))();
}
}
执行结果:

参考文章:
COM 组件设计与应用(八)——实现多接口 http://www.vckbase.com/index.php/wv/1236
COM组件双接口对象模型的更多相关文章
- COM组件多接口对象模型
COM组件有两种接口类型,Dual and Custom,如下图所示.本文说的是Custom.所谓多接口COM对象是指此COM对象实现了多于一个的自定义接口,即Custom接口. 接口图如下: 需要注 ...
- COM组件 IDispatch 及双接口的调用
转自:http://blog.csdn.net/cnhk1225/article/details/50555647 一.前言 前段时间,由于工作比较忙,没有能及时地写作.其间收到了很多网友的来信询问和 ...
- 【转载】COM 组件设计与应用(十一)—— IDispatch 及双接口的调用
原文:http://vckbase.com/index.php/wv/1236.html 一.前言 前段时间,由于工作比较忙,没有能及时地写作.其间收到了很多网友的来信询问和鼓励,在此一并表示感谢.咳 ...
- Android开发之自定义组件和接口回调
说到自定义控件不得不提的就是接口回调,在Android开发中接口回调用的还是蛮多的.在这篇博客开始的时候呢,我想聊一下iOS的自定义控件.在iOS中自定义控件的思路是继承自UIView, 在UIVie ...
- 【Android 应用开发】 自定义组件 宽高适配方法, 手势监听器操作组件, 回调接口维护策略, 绘制方法分析 -- 基于 WheelView 组件分析自定义组件
博客地址 : http://blog.csdn.net/shulianghan/article/details/41520569 代码下载 : -- GitHub : https://github.c ...
- COM组件三大接口IUnknown、IClassFactory、IDispatch。
转自:http://blog.csdn.net/chenyujing1234/article/details/7753863 (1)COM组件有三个最基本的接口类,分别是IUnknown.IClass ...
- 双接口(回调)promise cb
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【转载】COM 组件设计与应用(十)——IDispatch 接口 for VC.NET
原文:http://vckbase.com/index.php/wv/1225.html 一.前言 终于写到了第十回,我也一直期盼着写这回的内容耶,为啥呢?因为自动化(automation)是非常常用 ...
- 【转载】COM 组件设计与应用(九)——IDispatch 接口 for VC6.0
原文: http://vckbase.com/index.php/wv/1224.html 一.前言 终于写到了第九回,我也一直期盼着写这回的内容耶,为啥呢?因为自动化(automation)是非常常 ...
随机推荐
- spingboot启动报驱动Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of th
原因: springboot应用了最新的驱动com.mysql.cj.jdbc.Driver,这个驱动需要用mysql-connector-java包的6.x版本才可以, 而mysql-connect ...
- Flutter学习之Dart语言基础(构造函数)
最常见的构造函数形式,即生成构造函数,创建一个类的新实例: class Point { num x, y; //Dart中int和double是num的子类 //this引用当前类对象 Point(n ...
- 【leetcode】610. Triangle Judgement
原题 A pupil Tim gets homework to identify whether three line segments could possibly form a triangle. ...
- Matplotlib介绍
目录 一. Matplotlib介绍 1 二. 初级绘制 1 1. 绘图简介 1 2. 在上面的过程中,主要就是下面三个元素: 1 三. 2D各种 ...
- iptables网络防火墙和SNAT原理实战
网络防火墙 iptables/netfilter网络防火墙: (1) 充当网关 (2) 使用filter表的FORWARD链 注意的问题: (1) 请求-响应报文均会经由FORWARD链,要注意规则的 ...
- centos7下安装zookeeper&zookeeper集群的搭建
一.centos7下安装zookeeper 1.zookeeper 下载地址 https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 2.安装步骤 ...
- c信号量操作demo
#include <stdio.h> #include <string.h> #include <sys/ipc.h> #include <sys/sem.h ...
- MYSQL参数说明
[mysqld] character_set_server=utf8 #慢日志时间 long_query_time=1 #开启慢日志 slow_query_log=TRUE #慢日志位置 slow_q ...
- IPC五种通讯方式
IPC五种通讯方式 1.管道:速度慢,容量有限,只有父子进程能通讯 2.FIFO:任何进程间都能通讯,但速度慢 3.消息队列:容量受到系统限制,且要注意第一次读的时候,要考虑上一次没有读完数据的问题 ...
- 月球-I型,月份日历生成器----基于PHP7.3
生成月份周日的类 <?php class mycalendar { function __construct($year,$mon) { $'; $this->firstday=strto ...