COM Fundamentals

   

Before we dig into the COM support provided by C++Builder and examine related code examples, it's helpful to understand the fundamental elements of COM. For those familiar with COM, consider this a review.

COM is designed to enable modular elements of a program to be built so that they can be used by and within other programs. The benefits of COM and related COM-based technologies are two-fold:

  • COM specifies a standard at the binary level for developing and using components in any language or development tool.

  • COM provides transparency. The user of a component does not have to know where the component actually resides. Even if the component is in a remote server (using DCOM), the client uses it as a local component.

Essentially, COM provides a basis for building on your applications as a cooperative set of independent binary units. This produces an aspect of reusability sometimes referred to as componentware .

NOTE

COM has become a big part of Windows and provides a viable mechanism for object-oriented software developers. We can use COM to develop modular elements of a program that can be used by and within other programs. A current example includes the editor for Microsoft Paint, a COM-based program, which can be seamlessly integrated into Word. To see this example, open Word and choose Insert, Object, and Bitmap Image. A copy of the Paint editor should integrate into Word. This COM activity is called in-place activation and is touted as one of the Plug-and-Play features of Windows.

The applications you develop can also leverage capabilities available in other COM-based applications, such a Powerpoint and Word. One of the more recent COM-based applications provided by Microsoft that many application developers are taking advantage of is the Microsoft XML (MSXML) parser. Access to the MSXML parser is accomplished using COM. In fact, the TXMLDocument , which is a VCL class provided with Delphi and C++Builder, leverages COM to provide a VCL wrapper for the MSXML parser.


COM Architectural Elements

Five basic architecture elements of COM enable the development and distribution of componentware . These elements are described in Table 17.1. It's important to understand each one of these.

Table 17.1. COM Architecture Elements

Element

Description

COM Interface

Serves as a contract identifying the public methods used to access a COM object. Equivalent to an abstract class containing pure virtual functions in C++. Interfaces are used by a COM Client and recognized by a COM Server. Note that a COM interface defines usage not implementation.

COM Class

Represents the implementation of one or more COM interfaces, often referred to as a CoClass. Encapsulates the behavior associated to the methods and access to the properties identified in the COM interface declaration. Classes are implemented within a COM Server.

COM Object

The instantiation of a COM Class within a COM Server is a COM Object. A COM Object is accessed by a COM Client through the COM Interface.

COM Server

Provides the interface implementations that a client can use. A COM Class is instantiated as a COM Object within a COM Server. The two types of servers are out-of-process and in-process . A server that is its own application (EXE) operates as an out-of-process server. A server that is represented as DLL or ActiveX Control Library operates as an in-process server.

COM Client

Code or program that utilizes a COM interface to communicate with an object contained within a COM Server.

These five architectural elements are the basic tenants required for all things COM, including COM+ and Distributed COM (DCOM). For COM to work effectively each of these elements need to be in place. Figure 17.1 illustrates how these elements interoperate .

Figure 17.1. COM Client/Server communication via a COM Interface.

graphics/17fig01.gif

This illustrates how COM uses a client-server model. The server contains the COM Object accessed by a client via a COM Interface. Later in the chapter, we will look at how these architectural elements are developed and used with C++Builder.

COM Technologies

The other aspect of understanding COM fundamentals is to recognize the various COM technologies and extensions that exist. Table 17.2 provides a listing of the COM technologies supported by C++Builder.

Table 17.2. C++Builder COM Support

Item

Description

ActiveX Controls

A compiled software component representing a COM object whose properties can be altered at design time and can integrate and extend the functionality of an application at runtime.

ActiveX Library

An in-process server DLL that hosts one or more ActiveX controls or COM objects.

Property Page

A dialog that enables modification of ActiveX control properties at design time.

Active Form

A simple ActiveX control preconfigured to run on a Web browser. Descends from TActiveForm within C++Builder.

Active Server Object

A COM Object used to transform an existing application to an Active Server Page, which is a script that generates HTML pages and can act as an Automation controller.

Automation Controller

A client application that leverages and reflects capabilities exposed by Automation Objects that are contained within an external application.

Automation Objects

COM objects contained with an application called an Automation Server that can be controlled by other applications programmatically at runtime.

COM+ Event Object

A COM+ Object used for dispatching server events to registered clients . Facilitates publish/subscribe paradigm.

COM+ Subscription Object

A COM+ Object used for registering a client to receive notification of events fired by COM+ publisher applications.

Transactional Object

An element of COM+ allowing support for handling a large number of clients. Features include just-in-time activation, transactions, resource pooling, and security systems.

Type Library

Used to define custom interfaces, dispinterfaces, coclasses , enumerations, aliases, records, unions, and modules. Type libraries can be identified within the system registry for access by other applications.

As you can see, most of the COM technologies center on ActiveX, Automation and COM+. Also identified in this table is the concept of Type Libraries, which we will utilize in the next section by developing COM interfaces and classes.

NOTE

COM+ is an extension of COM that integrates Microsoft Transaction Server (MTS) and Microsoft Message Queue (MSMQ), which makes it more suitable for large-scale distributed development than standard COM. COM+ provides support for transaction control, security, administration, queued components, and publish-and-subscribe event services. COM+ provides a more scalable technology than standard COM, which includes Just-In-Time Activation and lifetime management. Although our discussion is largely focused on COM, keep in mind that the techniques and capabilities of COM discussed here are fully supported by COM+.



   
Top


C++ Builder Developers Guide
C++Builder 5 Developers Guide
ISBN: 0672319721
EAN: 2147483647
Year: 2002
Pages: 253

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net