[ Pobierz całość w formacie PDF ]
." Instancing: Unless you are creating an in-process server, you need to indicate howCOM launches the application that houses your COM object.If your applicationimplements more than one COM object, you should specify the same instancingfor all of them.For information on the different possibilities, see COM objectinstancing types on page 43-6." Threading Model: Typically, client requests to your object enter on differentthreads of execution.You can specify how COM serializes these threads when itcalls your object.Your choice of threading model determines how the object isregistered.You are responsible for providing any threading support implied bythe model you choose.For information on the different possibilities, see COMobject instancing types on page 43-6.For information on how to provide threadsupport to your application, see Chapter 13, Writing multi-threadedapplications." Event support: You must indicate whether you want your object to generateevents to which clients can respond.The wizard can provide support for theinterfaces required to generate events and the dispatching of calls to client eventhandlers.For information on how events work and what you need to do whenimplementing them, see Exposing events to clients on page 43-11.Cr eat i ng s i mpl e COM s er v er s 43-5Us i n g t h e Au t o ma t i o n o b j e c t wi z a r dYou can optionally add a description of your COM object.This description appearsin the type library for your object.The Automation object implements a dual interface, which supports both early(compile-time) binding through the VTable and late (runtime) binding through theIDispatch interface.For more information, see Dual interfaces on page 43-13.COM object instancing typesMany of the COM wizards require you to specify an instancing mode for the object.Instancing determines how many instances of your object clients can create in asingle executable.If you specify a Single Instance model, for example, then once aclient has instantiated your object, COM removes the application from view so thatother clients must launch their own instances of the application.Because this affectsthe visibility of your application as a whole, the instancing mode must be consistentacross all objects in your application that can be instantiated by clients.That is, youshould not create one object in your application that uses Single Instance mode andanother in the same application that uses Multiple Instance mode.Note Instancing is ignored when your COM object is used only as an in-process server.When the wizard creates a new COM object, it can have any of the followinginstancing types:Instancing MeaningInternal The object can only be created internally.An external application cannotcreate an instance of the object directly, although your application can createthe object and pass an interface for it to clients.Single Instance Allows clients to create only a single instance of the object for each executable(application), so creating multiple instances results in launching multipleinstances of the application.Each client has its own dedicated instance of theserver application.Multiple Instances Specifies that multiple clients can create instances of the object in the sameprocess space.Choosing a threading modelWhen creating an object using a wizard, you select a threading model that yourobject agrees to support.By adding thread support to your COM object, you canimprove its performance, because multiple clients can access your application at thesame time.43-6 Devel oper s Gui deUs i n g t h e Au t o ma t i o n o b j e c t wi z a r dTable 43.1 lists the different threading models you can specify.Table 43.1 Threading models for COM objectsThreading model Description Implementation pros and consSingle The server provides no thread Clients are handled one at a time so nosupport.COM serializes client threading support is needed.requests so that the applicationNo performance benefit.receives one request at a time.Apartment COM ensures that only one Objects can safely access their own(or Single-threaded client thread can call the object instance data, but global data must beapartment) at a time
[ Pobierz całość w formacie PDF ]