Creating simple COM servers

C++Builder provides wizards to help you create various COM objects. The simplest COM objects are servers that expose properties and methods (and possibly events) through a default interface that clients can call.

C++Builder提供了向导可以帮助开发者创建不同的COM对象。最简单的COM对象时一种服务器,它可以通过默认的接口让客户端来访问公开的属性,方法以及可能存在的事件

Note: COM servers and Automation is not available for use in CLX applications. This technology is for use on Windows only and is not cross-platform.

注意:COM servers和Automation在使用CLX的程序中是无效的。这项技术只能在windows中使用,不支持跨平台操作!

Two wizards, in particular, ease the process of creating simple COM objects:

The COM Object wizard builds a lightweight COM object whose default interface descends from IUnknown or that implements an interface already registered on your system. This wizard provides the most flexibility in the types of COM objects you can create.

COM对象向导产生一个轻量的COM对象,它可以派生自IUnknown或者系统中已经注册的实现。
The Automation Object wizard creates a simple Automation object whose default interface descends from IDispatch. IDispatch introduces a standard marshaling mechanism and support for late binding of interface calls.

Automation Object向导创建一个简单的Automation Object。它是一个派生自IDispatch的接口。IDispatch提供了一个标准的封装机制,并且支持接口的后期绑定

Note: COM defines many standard interfaces and mechanisms for handling specific situations. The C++Builder wizards automate the most common tasks. However, some tasks, such as custom marshaling, are not supported by any C++Builder wizards. 

COM 定义许多标准接口机制处理具体情况。BCB提供的向导可以完成大部分任务,但是不能自动完成自定义封装的处理。

Overview of creating a COM object

Whether you use the Automation object wizard to create a new Automation server or the COM object wizard to create some other type of COM object, the process you follow is the same. It involves these steps:

1 Design the COM object.设计COM对象
2 Use the COM Object wizard or the Automation Object wizard to create the server object.使用向导创建对应的object
3 Specify options on the ATL page of the project options dialog to indicate how COM will call the application that houses your object and what type of debugging support you want.指定ATL选项卡上的选项
4 Define the interface that the object exposes to clients.定义对客户端公开的接口
5 Register the COM object.注册COM对象
6 Test and debug the application.测试、调试

Designing a COM object

When designing the COM object, you need to decide what COM interfaces you want to implement. You can write a COM object to implement an interface that has already been defined, or you can define a new interface for your object to implement. In addition, you can have your object support more than one interface. For information about standard COM interfaces that you might want to support, see the MSDN documentation.

To create a COM object that implements an existing interface, use the COM Object wizard.创建一个已经存在的接口的实现,使用COM Object Wizard
To create a COM object that implements a new interface that you define, use either the COM Object wizard or the Automation Object wizard. The COM object wizard can generate a new default interface that descends from IUnknown, and the Automation object gives your object a default interface that descends from IDispatch. No matter which wizard you use, you can always use the Type Library editor later to change the parent interface of the default interface that the wizard generates.无乱使用哪种向导创建,随后都可以使用Type Library Editor来改变它的父接口。

In addition to deciding what interfaces to support, you must decide whether the COM object is an in-process server, out-of-process server, or remote server. For in-process servers and for out-of-process and remote servers that use a type library, COM marshals the data for you. Otherwise, you must consider how to marshal the data to out-of-process servers.另外,还需要决定,到底是要创建进程

 
 

posted on 2014-10-31 14:02  liyinglr  阅读(112)  评论(0)    收藏  举报

导航