- 作者:xiaoxiao
- 发表时间:2020-12-23 11:01
- 来源:未知
InProcSever32进程内COM服务器LocalSever32进程外COM服务器
InProcSever:delphi创建进程内com服务器的过程:CreateComObject(const ClassID:TGUID):IUnknown其ClassID是接口类的CLSID,在此函数内部会调用CoCreateInstance,CoCreateInstance封装了CoGetClassObject.CoCreateInstance:Creates a single uninitialized object of the class associated with a specified CLSID.Call CoCreateInstance when you want to create only one object on the local system. To create a single object on a remote system, call CoCreateInstanceEx. To create multiple objects based on a single CLSID, refer to the CoGetClassObject function.
It is convenient to use CoCreateInstance when you need to create only a single instance ofan object on the local machine. If you are creating an instance on remote machine, call CoCreateInstanceEx. When you are creating multiple instances, it is more efficient to obtain a pointer to the class object's IClassFactory interface and use its methods as needed. In the latter case, you should use the CoGetClassObject function.
CoCreateInstance内部调用CoGetClassObject,搜索注册标,获得该COM类所在的DLL位置并加载,通过调用在该DLL导出的函数获DllGetClassObject得接口类的Class Factory,通过调用该类厂的的方法CreateInstance最终获得需要的接口指针。如上英文所注:当要创建一个COM类的多个实例时,应该直接调用CoGetClassObject获得类厂指针,然后调用类厂的方法CreateInstance创建接口。CreateComObject-->CoCreateInstance-->CoGetClassObject--->DllGetClassObject---->CreateInstance
LocalSever32delphi创建进程外COM服务器的过程:CreateComObject(const ClassID:TGUID):IUnknown其ClassID是接口类的CLSID,CreateComObject-->CoCreateInstance--->CoGetClassObject--->CreateProcess-->CoRegisterClassObject--->CreateInstance
聚合:一般来说,要重用一个delphi 对象或C++对象可以通过继承或组合的方式,那么要冲用COM对象(实现了接口的COM类),则是通过聚合的方式,有点类似普通对象的组合,但不同的是,聚合类必须包装被聚合类的接口方法,当客户调用聚合类引出的包装的方法时,聚合类将客户调用转入被聚合的类的相应方法。
DCOM:CreateRemoteComObject-->CoCreateInstanceEx-->CoGetClassObject--CreateInstance;
自动化:本质上是实现了IDispatch接口的COM对象。自动化的例子,比如在word中可以编辑Excel表格,可以编辑图片等。它是一种应用程序或DLL暴漏可编程控制对象给其他应用程序的技术。提供这种对象的应用叫自动化服务器,访问这种对象的应用叫自动化控制器。自动化最大的优势是语言无关。一个自动化控制器可以控制任何一门语言开发的自动化服务器。
type TButtonEdit = class(TWinControl) private { Private declarations } protected { Protected declarations } public { Public declarations } published { Published declarations } end;