[ Pobierz całość w formacie PDF ]
.TLB and the Project_TLB unit to disk." Refresh, to update the type library units in memory only." Register, to add an entry for the type library in your system s Windows registry.This is done automatically when the server with which the.TLB is associated isitself registered." Export, to save a.IDL file that contains the type and interface definitions in IDLsyntax.All the above methods perform syntax checking.When you refresh, register, or savethe type library, C++Builder automatically updates the implementation unit of anyCoClasses that were created using a wizard.Saving a type librarySaving a type library" Performs a syntax and validity check." Saves information out to a.TLB file." Saves information out to the Project_TLB unit." Notifies the IDE s module manager to update the implementation, if the typelibrary is associated with a CoClass that was generated by a wizard.To save the type library, choose File|Save from the C++Builder main menu.Wor k i ng wi t h t ype l i br ar i es 33-17De p l o y i n g t y p e l i b r a r i e sRefreshing the type libraryRefreshing the type library" Performs a syntax check." Regenerates the C++Builder type library units in memory only.It does not saveany files to disk." Notifies the IDE s module manager to update the implementation, if the typelibrary is associated with a CoClass that was generated by a wizard.To refresh the type library choose the Refresh icon on the Type Library editor toolbar.Note If you have renamed items in the type library, refreshing the implementation maycreate duplicate entries.In this case, you must move your code to the correct entryand delete any duplicates.Similarly, if you delete items in the type library, refreshingthe implementation does not remove them from CoClasses (under the assumptionthat you are merely removing them from visibility to clients).You must delete theseitems manually in the implementation unit if they are no longer needed.Registering the type libraryTypically, you do not need to explicitly register a type library because it is registeredautomatically when you register your COM server application (see Registering aCOM object on page 35-16).However, when you create a type library using theType Library wizard, it is not associated with a server object.In this case, you canregister the type library directly using the toolbar.Registering the type library," Performs a syntax check" Adds an entry to the Windows Registry for the type libraryTo register the type library, choose the Register icon on the Type Library editortoolbar.Exporting an IDL fileExporting the type library," Performs a syntax check." Creates an IDL file that contains the type information declarations.This filedescribes the type information in Microsoft IDL.To export the type library, choose the Export icon on the Type Library editor toolbar.Deploying type librariesBy default, when you have a type library that was created as part of an ActiveX orAutomation server project, the type library is automatically linked into the.DLL,.OCX, or EXE as a resource.33-18 Dev el oper s Gui deDe p l o y i n g t y p e l i b r a r i e sYou can, however, deploy your application with the type library as a separate.TLB,as C++Builder maintains the type library, if you prefer.Historically, type libraries for Automation applications were stored as a separate filewith the.TLB extension.Now, typical Automation applications compile the typelibraries into the.OCX or.EXE file directly.The operating system expects the typelibrary to be the first resource in the executable (.DLL,.OCX, or.EXE) file.When you make type libraries other than the primary project type library available toapplication developers, the type libraries can be in any of the following forms:" A resource.This resource should have the type TYPELIB and an integer ID.If youchoose to build type libraries with a resource compiler, it must be declared in theresource (.RC) file as follows:1 typelib mylib1.tlb2 typelib mylib2.tlbThere can be multiple type library resources in an ActiveX library.Applicationdevelopers use the resource compiler to add the.TLB file to their own ActiveXlibrary." Stand-alone binary files.The.TLB file output by the Type Library editor is a binaryfile.Wor k i ng wi t h t ype l i br ar i es 33-1933-20 Dev el oper s Gui deCh a p t e r34Chapter34Creating COM clientsCOM clients are applications that make use of a COM object implemented by anotherapplication or library.The most common types are applications that control anAutomation server (Automation controllers) and applications that host an ActiveXcontrol (ActiveX containers).At first glance these two types of COM client are very different: The typicalAutomation controller launches an external server EXE and issues commands tomake that server perform tasks on its behalf.The Automation server is usuallynonvisual and out-of-process.The typical ActiveX client, on the other hand, hosts avisual control, using it much the same way you use any control on the Componentpalette.ActiveX servers are always in-process servers.However, the task of writing these two types of COM client is remarkably similar:The client application obtains an interface for the server object and uses its propertiesand methods.C++Builder makes this particularly easy by letting you wrap the serverCoClass in a component on the client, which you can even install on the Componentpalette.Samples of such component wrappers appear on two pages of theComponent palette: sample ActiveX wrappers appear on the ActiveX page andsample Automation objects appear on the Servers page.When writing a COM client, you must understand the interface that the serverexposes to clients, just as you must understand the properties and methods of acomponent from the Component palette to use it in your application.This interface(or set of interfaces) is determined by the server application, and typically publishedin a type library.For specific information on a particular server application spublished interfaces, you should consult that application s documentation.Even if you do not choose to wrap a server object in a component wrapper and installit on the component palette, you must make its interface definition available to yourapplication.To do this, you can import the server s type information.Cr eat i ng COM c l i ent s 34-1I mp o r t i n g t y p e l i b r a r y i n f o r ma t i o nNote You can also query the type information directly using COM APIs, but C++Builderprovides no special support for this.Some older COM technologies, such as object linking and embedding (OLE), do notprovide type information in a type library.Instead, they rely on a standard set ofpredefined interfaces.These are discussed in Creating Clients for servers that do nothave a type library on page 34-16.Importing type library informationTo make information about the COM server available to your client application, youmust import the information about the server that is stored in the server s typelibrary.Your application can then use the resulting generated classes to control theserver object
[ Pobierz całość w formacie PDF ]