- Table of Contents
- Copyright
- About the Authors
- About the Contributors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- How to Use This Book
- What You Need to Use This Book
- What's New in Visual C++ 6.0
- Contacting the Main Author
- Part I: Introduction
- Chapter 1. The Visual C++ 6.0 Environment
- Part II: MFC Programming
- Chapter 2. MFC Class Library Overview
- Chapter 3. MFC Message Handling Mechanism
- Chapter 4. The Document View Architecture
- Chapter 5. Creating and Using Dialog Boxes
- Chapter 6. Working with Device Contexts and GDI Objects
- Chapter 7. Creating and Using Property Sheets
- Chapter 8. Working with the File System
- Chapter 9. Using Serialization with File and Archive Objects
- Part III: Internet Programming with MFC
- Chapter 10. MFC and the Internet Server API (ISAPI)
- Chapter 11. The WinInet API
- Chapter 12. MFC HTML Support
- Part IV: Advanced Programming Topics
- Chapter 13. Using the Standard C++ Library
- Chapter 14. Error Detection and Exception Handling Techniques
- Chapter 15. Debugging and Profiling Strategies
- Chapter 16. Multithreading
- Chapter 17. Using Scripting and Other Tools to Automate the Visual C++ IDE
- Part V: Database Programming
- Chapter 18. Creating Custom AppWizards
- Chapter 19. Database Overview
- Chapter 20. ODBC Programming
- Chapter 21. MFC Database Classes
- Chapter 22. Using OLE DB
- Chapter 23. Programming with ADO
- Part VI: MFC Support for COM and ActiveX
- Chapter 24. Overview of COM and Active Technologies
- Chapter 25. Active Documents
- Chapter 26. Active Containers
- Chapter 27. Active Servers
- Chapter 28. ActiveX Controls
- Part VII: Using the Active Template Library
- Chapter 29. ATL Architecture
- Chapter 30. Creating COM Objects Using ATL
- Chapter 31. Creating ActiveX Controls Using ATL
- Chapter 32. Using ATL to Create MTS and COM+ Components
- Understanding Transactions
- COM+ and MTS Features
- An Example of a COM+ Application
- Summary
- Part VIII: Finishing Touches
- Chapter 33. Adding Windows Help
- Part IX: Appendix
COM+ and MTS Features
MTS introduced basic support for creating multitier applications with transaction support. MTS 1.0 was really an application that was layered on top of the Windows NT 4.0 operating system, and many features that are expected in a transaction support system weren't present.
COM+ is more tightly integrated than MTS and takes advantage of that integration to provide a wide range of features that simply weren't possible in MTS.
Understanding Contexts
The context is a new concept introduced with COM+ in Windows 2000. All COM and COM+ components execute in contexts, which are sets of execution attributes that define transaction, synchronization, and other characteristics for components. Each process is partitioned into one or more contexts, much as processes previously were portioned into apartments.
Today in Windows 2000, the apartment is now just one part of an object's context. Two components that are identical except for their apartment membership will live in separate contexts. In a similar way, components with different transaction support will execute in separate contexts.
Direct communication between contexts is not allowed. Instead, lightweight interception proxies are used as communication channels between components in separate contexts. These interception proxies work very much like the proxies used to marshal data between apartments prior to the introduction to COM+.
Interception proxies are not invoked explicitly. Instead, the operating system detects that components in incompatible contexts are attempting to communicate and marshals the communication via an interception proxy.
Concurrency in COM+
In COM, concurrency and synchronization were enforced using apartments. In reality, the apartment actually controlled thread affinity rather than concurrency; synchronization was a side effect of the thread-affinity restriction. In a single-threaded apartment (STA), only one thread is permitted to visit an apartment; therefore, it is not possible to have thread-synchronization issues. In a multi-threaded apartment (MTA), any thread in the apartment may visit a component, so thread-synchronization issues must be addressed by the component.
The problem with using apartments for synchronization is that the concept of an apartment is not fine-grained. In COM+, the apartment is still used, but it now is used for thread-affinity purposes. For synchronization, COM+ introduces the activity. An activity is a collection of one or more components grouped together. Only one call is permitted in a single activity at any given time. This method allows for fine-grained control over component synchronization, because it separates thread affinity from concurrency. In COM+, it is possible to have components that exist in an MTA and can be visited by multiple threads, while relying on the operating system for synchronization.
Just-In-Time Activation
One of the key features offered by MTS and COM+ is just-in-time (JIT) activation. With JIT activation, references to objects are created when a client creates an instance of a configured component. The COM+ (or MTS) runtime does not automatically create a real instance of the component, however, and waits until the client makes a method call toward the component. After the method call, the component is deactivated and returned to a pool of components available for the next method call.
Just-in-time activation enables many clients to share small pools of components in an efficient manner. Just-in-time activation is enabled automatically for components that support or require transactions. If you enable JIT activation, your component also is configured automatically to require synchronization.
What Is Object Pooling?
Object pooling is similar to JIT activation. In object pooling, the operating system pre allocates a pool of components that are ready to be used by clients. Object pooling is useful when clients are sensitive to the initial startup costs of activating components. When providing components for Web servers, for example, you will get better performance by taking advantage of object pooling.
Registering a COM+ Application
COM+ components are grouped into COM+ applications. The first step in registering one or more COM+ components is to create a COM+ application that contains the component(s).
To register a COM+ component, launch the COM+ MMC snap-in, and expand the tree below Component Services until you reach the COM+ applications node. Figure 32.1 shows the COM+ MMC snap-in with the Component Services tree expanded to show currently configured COM+ applications. New COM+ applications are added to this portion of the tree.
Figure 32.1 The COM+ MMC snap-in.
You add new applications by right-clicking on the COM+ Applications icon. Choose New, Application from the context menu. The COM Application Install Wizard appears. Initially, a welcome message is displayed. If you click Next, you move to the second wizard page, shown in Figure 32.2.
Figure 32.2 Installing a COM+ application.
The page in Figure 32.2 offers two options:
- Install an application that is supplied to you as a prebuilt application. You can use this option to install applications that are exported from an existing installation.
- Install an empty application. This option creates an empty application that contains no COM+ components.
This chapter does not cover redistributing and installing prebuilt COM+ applications. To create a new application, click the Create an Empty Application button. The next wizard page appears, as shown in Figure 32.3.
Figure 32.3 Defining the name and activation type.
You use this wizard page to enter the name of the COM+ application. You also can specify the type of activation to be used for the new application:
- Library Application specifies that the COM+ application will run in the process of the client. This option is rather limited and is rarely used.
- Server Application specifies that the COM+ application will run in a process managed by the operating system. This is the option that is usually selected.
After filling in this wizard page, click Next to display a page that lets you set the application identity (see Figure 32.4).
Figure 32.4 Defining the name and application type.
You use this wizard page to specify the security principal that will be used to execute the COM+ application. For debugging and testing purposes, the easiest approach is to choose the interactive user option. For a COM+ application deployed in a production environment, you should specify a security context to be used to execute the application.
This is the last wizard page. Click Next to display a thank-you message.
Configuring Properties for a COM+ Application
After a COM+ application is installed, you can access the application's properties by right-clicking the COM+ application's icon and choosing Properties from the context menu. The application's properties sheet appears, as shown in Figure 32.5.
Figure 32.5 The COM+ application properties sheet.
You use the first tab on the properties sheet, the General tab, to specify the name and description of the application. The GUID associated with the application also is displayed.
You use the Security tab, shown in Figure 32.6, to specify security attributes for the application, including these:
Figure 32.6 The Security tab.
- Enforce Access Checks for This Application. You select this option to enable role-based security checking.
- Security Level. By default, security access checks are performed at the component and process level. You also can elect to perform checks at only the process level.
- Authentication Level for Calls. You use this combo box to specify the security level that is used when information is passed to or from a COM+ application.
- Impersonation Level. You use this combo box to specify the type of impersonation available to a COM+ application.
You use the Identity tab, shown in Figure 32.7, to specify the security principal that will be used to execute the COM+ application.
Figure 32.7 The Identity tab.
The Activation tab specifies how the application will be activated (see Figure 32.8). You have the same options you had when the application was created: The application may be activated in the client's process, a library application, or a process managed by COM+—a server application.
Figure 32.8 The Activation tab.
The Queuing tab specifies characteristics for queued components (see Figure 32.9). You can choose from two check boxes:
Figure 32.9 The Queuing tab.
- Enable Queued if the COM+ application can receive messages from message queues.
- Enable Listen if the Queued option is selected. If you select this option, the application listens for messages that arrive from the message queue.
You use the Advanced tab, shown in Figure 32.10, to specify various advanced options for the COM+ application:
Figure 32.10 The Advanced tab.
- Server Process Shutdown. This area specifies whether and when the application should be shut down. You can specify that the application should never be shut down, or that it should shut down after being idle for a specified period of time.
- Permission. You can use these options to specify that client applications cannot change or delete the COM+ application.
- Debugging. You choose this to enable the application to be launched in a specific debugger.
- Enable Compensating Resource Managers. You use compensating resource managers when using resources that do not directly support transactions.
- Enable 3GB Support. This option enables the application to access up to 3 gigabytes of memory when using Windows 2000 Advanced Server.
Registering a COM+ Component
When a COM+ application is created, it has no components associated with it. After your COM+ application is installed and configured, your next step is to add one or more components to the COM+ application.
To install a COM+ component, expand the tree under the COM+ application node in the COM+ MMC snap-in. Right-click on the Components folder, and then choose New, Component from the context menu. The COM+ Component Install Wizard appears. Click Next to move from the welcome page and begin working with the wizard (see Figure ).
Figure 32.11 The COM+ Component Install Wizard.
This wizard page has three options:
- Install New Component(s). Installs a new component that had not been registered previously.
- Import Component(s) That Are Already Registered. Registers a COM+ component that was registered previously as a nonconfigured COM component.
- Install New Event Class(es). Installs classes that will be used with COM+ events.
In most cases, you will add new components to your COM+ application by clicking the Install New Components button.
After clicking one of the options on the wizard page just described, the File Open dialog box appears. Navigate to the DLL that houses your COM+ component, and click the Open button. The wizard page shown in Figure 32.12 appears.
Figure 32.12 The COM+ Component Install Wizard.
This wizard page displays the components found in the selected module. This is the last wizard page; to move to the thank-you page, click Next. Click Finish on the thank-you page to dismiss the wizard.
Configuring Properties for a COM+ Component
After registration, you can configure a COM+ component via its properties sheet, which you can display by right-clicking on the component in the COM+ Explorer snap-in and choosing Properties from the context menu. The properties sheet includes six properties pages you can use to configure the component (see Figure ).
Figure 32.13 The Object Pro perties dialog box.
General Properties
The General Properties page displays information about the COM+ component, such as its description, class ID, location, and application GUID.
Transactions Properties
You use the Transactions Properties page to define the transaction requirements for a COM+ object (see Figure 32.14).
Figure 32.14 The Transactions Properties page.
The transaction support required for the COM+ object may be one of the following values:
- Disabled. This option eliminates all transaction-related overhead when executing the COM+ component.
- Not Supported. The component does not participate in transactions.
- Supported. The component participates in a transaction if it is called in the context of an existing transaction. The component does not create a new transaction if it is called in a nontransaction context, however.
- Required. The component must run in a transaction context. The component creates a new transaction, if necessary, but also participates in an existing transaction if it is called in a transaction context.
- Requires New. The component must run in a new transaction context, creating a new, nested transaction if necessary.
If you select the Required or Requires New option for transaction support, you can override the default transaction timeout by enabling the Override Global Transaction Timeout Value check box. Checking this box enables the edit control that collects the new transaction timeout value.
Security Properties
You use the Security Properties page to define the security attributes for a COM+ component (see Figure 32.15).
Figure 32.15 The Security Properties page.
To take advantage of component-level security, you must enable the Enforce Component Level Access Checks check box. In addition, component and process-level access checking must have been enabled for the COM+ application.
Roles defined for the application are listed in the lower half of the Properties page. Each role that is explicitly granted access to this component has a check next to its name.
Activation Properties
You use the Activation Properties page to define the activation semantics for a COM+ component (see Figure 32.16).
Figure 32.16 The Activation Properties page.
You can enable object pooling by enabling the Enable Object Pooling check box. If this option is enabled, you may optionally specify the minimum and maximum size of the object pool, as well as the amount of time allowed for object creation. If no object can be provided to a caller before this timeout expires, an error is returned to the caller.
You can enable object construction with the Support Object Construction check box. When this option is enabled, a construction string is passed to the component if the component supports the IObjectConstruction interface.
You can enable just-in-time activation using the Activation Properties page. This option is required for components that support or require transaction support.
To view event and statistic information about your component, enable the Component Supports Events and Statistics check box.
The last check box, Must Be Activated in Caller's Context, prevents a component from being created via a proxy. If a caller attempts to activate the component from an incom patible context, the call will fail instead of activating the component through a proxy.
Concurrency Properties
You use the Concurrency Properties page to define the concurrency and synchronization semantics for a COM+ component (see Figure 32.17).
Figure 32.17 The Concurrency Properties page.
You cannot change the threading model for the COM+ object by using this Properties page; the threading model is displayed for informational purposes only.
The synchronization support required for the COM+ object may be one of the following values:
- Disabled. This option eliminates all synchronization-related overhead when using the component.
- Not Supported. The component never executes with synchronization support.
- Supported. The component directly participates in a context that requires synchronization without requiring a proxy. The component does not create a new synchronization activity if called in a nonsynchronization context, however.
- Required. The component must run in a context that supports synchronization. The component creates a new synchronization activity, if necessary, but also participates in an existing activity if called in a context that requires synchronization.
- Requires New. The component must run in a new synchronization activity context, creating a new activity if necessary.
If just-in-time activation is enabled for the component, only the Required and Requires New options are available.
Advanced Properties
You can use the Advanced Properties page to define the exception component class to be used for queued components. If defined, this class is used instead of sending messages to the dead letter queue. The exception class is expected to support the same queued interfaces as the original class.
The Advanced Properties page has no effect for non-queued components.
An Example of a COM+ Application | Next Section

Account Sign In
View your cart