APP下载

COM组件技术探究

2017-03-21张春艳张海波

电脑知识与技术 2016年33期

张春艳+张海波

摘要:COM Component(COM组件)技术是开发软件组件的方法,是微软公司为了解决软件复用,缩短软件开发时间而开发的一种新的软件开发技术。对COM组件的接口、COM组件的实现以及与普通DLL的区别进行了探究,以COM组件开发为研究视角,对COM组件开发的原理和方法进行分析,结合实例说明具体的开发步骤,并对COM组件在PHP上的调用方法做了具体示例。

关键词:COM;组件对象模型;接口

中图分类号:TP391 文献标识码:A 文章编号:1009-3044(2016)33-0096-03

Abstract: COM (Component Object Model) component technology is a method of developing software components. It is a new software development technology developed by Microsoft Corporation in order to solve software reuse and shorten software development time. This paper mainly discusses the interface of COM component, the realization of COM component and the difference between it and common DLL. It analyzes the principle and method of COM component development from the perspective of COM component development. Combined with an example to describes the specific development steps and calling the COM component on PHP.

Key words: COM; Component Object Model; Interface

1 概述

COM组件技术是一种十分完善的面向对象的技术规范。通常是以WIN32动态链接库(DLL)或可执行文件(EXE)的形式发布的可执行代码组成的,可以在跨平台条件下实现调用,对于代码重用有很大的意义。COM组件的核心思想是定义软件中可以重用的部分,实现代码复用。

COM组件的核心是组件和接口。其中组件是具有一定逻辑功能的可执行代码,而接口实现了对组件代码的封装与隔离。通常情况下一个有两个接口的COM组件如图1所示:

2 COM组件接口

COM组件最重要的部分是组件的接口。COM组件通过接口与外界进行联系,外界使用COM组件也必须知道COM组件的接口。因此COM组件的接口在系统中起着决定性作用。每个COM组件都必须有这三个接口:IUnknown、IClassFactory和IDispatch,其他接口都是直接或间接从这个接口派生而来。

2.1 基本接口

COM组件的基本接口是Iunknown接口,在COM组件中所有接口都以“I”开头。Iunknown接口的主要作用是对COM组件的所有接口进行标准化,以方便调用COM组件。COM组件的接口都必须符合一定的规范,在这……

登录APP查看全文