, Builder 5 Developers Guide 

[ Pobierz całość w formacie PDF ]
.){HandleException();}}}Warning Server sockets cache the threads they use.Be sure the ClientExecute method performsany necessary initialization so that there are no adverse results from changes madewhen the thread last executed.To use your thread, create it in an OnGetThread event handler.When creating thethread, set the CreateSuspended parameter to false.31-14 Dev el oper  s Gui de P a r tIVPart IVDeveloping COM-based applicationsThe chapters in  Developing COM-based applications present concepts necessaryfor building COM-based applications, including Automation controllers,Automation servers, ActiveX controls, and COM+ applications.Note Support for COM clients is available in all editions of C++Builder.However, to createservers, you need the Professional or Enterprise edition.Dev el opi ng COM- bas ed appl i c at i ons Ch a p t e r32Chapter 32Overview of COM technologiesC++Builder provides wizards and classes to make it easy to implement applicationsbased on the Component Object Model (COM) from Microsoft.With these wizards,you can create COM-based classes and components to use within applications or youcan create fully functional COM clients or servers that implement COM objects,Automation servers (including Active Server Objects), ActiveX controls, orActiveForms.COM is a language-independent software component model that enables interactionbetween software components and applications running on a Windows platform.The key aspect of COM is that it enables communication between components,between applications, and between clients and servers through clearly definedinterfaces.Interfaces provide a way for clients to ask a COM component whichfeatures it supports at runtime.To provide additional features for your component,you simply add an additional interface for those features.Applications can access the interfaces of COM components that exist on the samecomputer as the application or that exist on another computer on the network using amechanism called Distributed COM (DCOM).For more information on clients,servers, and interfaces see,  Parts of a COM application, on page 32-2.This chapter provides a conceptual overview of the underlying technology on whichAutomation and ActiveX controls are built.Later chapters provide details on creatingAutomation objects and ActiveX controls in C++Builder.COM as a specification and implementationCOM is both a specification and an implementation.The COM specification defineshow objects are created and how they communicate with each other.According tothis specification, COM objects can be written in different languages, run in differentprocess spaces and on different platforms.As long as the objects adhere to thewritten specification, they can communicate.This allows you to integrate legacy codeas a component with new components implemented in object-oriented languages.Over vi ew of COM t echnol ogi es 32-1 Pa r t s o f a COM a p p l i c a t i o nThe COM implementation is in the COM library (including OLE32.dll andOLEAut32.dll), which provides a number of core services that support the writtenspecification.The COM library contains a set of standard interfaces that define thecore functionality of a COM object, and a small set of API functions designed for thepurpose of creating and managing COM objects.When you use C++Builder wizards and VCL objects in your application, you areusing C++Builder s implementation of the COM specification.In addition,C++Builder provides some wrappers for COM services for those features that it doesnot implement directly (such as Active Documents).Note C++Builder implements objects conforming to the COM specification by using theMicrosoft Active Template Library (ATL), modified by classes and macros.COM extensionsAs COM has evolved, it has been extended beyond the basic COM services.COMserves as the basis for other technologies such as Automation, ActiveX controls,Active Documents, and Active Directories.For details on COM extensions, see COM extensions on page 32-9.In addition, when working in a large, distributed environment, you can createtransactional COM objects.Prior to Windows 2000, these objects were notarchitecturally part of COM, but rather ran in the Microsoft Transaction Server (MTS)environment.With the advent of Windows 2000, this support is integrated intoCOM+.Transactional objects are described in detail in Chapter 38,  Creating MTS orCOM+ objects.C++Builder provides wizards to easily implement applications that incorporate theabove technologies in the C++Builder environment.For details, see  ImplementingCOM objects with wizards on page 32-17.Parts of a COM applicationWhen implementing a COM application, you supply the following:COM Interface The way in which an object exposes its services externally toclients.A COM object provides an interface for each set of relatedmethods and properties.Note that COM properties are notidentical to properties on VCL objects.COM properties always useread and write access methods, and are not declared using the__property keyword.32-2 Dev el oper  s Gui de Pa r t s o f a COM a p p l i c a t i o nCOM server A module, either an EXE, DLL, or OCX, that contains the code for aCOM object.Object implementations reside in servers.A COMobject implements one or more interfaces.COM client The code that calls the interfaces to get the requested services fromthe server.Clients know what they want to get from the server(through the interface); clients do not know the internals of howthe server provides the services.C++Builder eases the process increating a client by letting you install COM servers (such as a Worddocument or Powerpoint slide) as components on the ComponentPalette.This allows you to connect to the server and hook itsevents through the Object Inspector.COM interfacesCOM clients communicate with objects through COM interfaces.Interfaces aregroups of logically or semantically related routines which provide communicationbetween a provider of a service (server object) and its clients.The standard way todepict a COM interface is shown in Figure 32.1:Figure 32.1 A COM interfaceInterfaceCOMObjectFor example, every COM object implements the basic interface, IUnknown, whichtells the client what interfaces are available on the COM object.Objects can have multiple interfaces, where each interface implements a feature.Aninterface provides a way to convey to the client what service it provides, withoutproviding implementation details of how or where the object provides this service.Key aspects of COM interfaces are as follows:" Once published, interfaces are immutable; that is, they do not change.You can relyon an interface to provide a specific set of functions.Additional functionality isprovided by additional interfaces." By convention, COM interface identifiers begin with a capital I and a symbolicname that defines the interface, such as IMalloc or IPersist." Interfaces are guaranteed to have a unique identification, called a GloballyUnique Identifier (GUID), which is a 128-bit randomly generated number.Interface GUIDs are called Interface Identifiers (IIDs) [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • anikol.xlx.pl