O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning DCOM

Book Description

DCOM -- the Distributed Component Object Model -- is a recent upgrade of a time-honored and well-tested technology promoted by Microsoft for distributed object programming. Now that components are playing a larger and larger part in Windows 98, Windows NT 4.0, and Windows 2000, every Windows programmer will want to understand the technology. DCOM competes with CORBA as a rich and robust method for creating expandable and flexible components, allowing you to plug in new parts conveniently and upgrade without the need for code changes to every program that uses your component.This book introduces C++ programmers to DCOM and gives them the basic tools they need to write secure, maintainable programs. While using Visual C++ development tools and wizards where appropriate, the author never leaves the results up to magic. The C++ code used to create distributed components and the communications exchanged between systems and objects are described at a level where the reader understands their significance and can use the insights for such tasks as debugging and improving performance.The first few chapters explain both the remote procedure calls that underlie DCOM's communication and the way DCOM uses C++ classes. Readers become firmly grounded in the relation between components, classes, and objects, the ways objects are created and destroyed, how clients find servers, and the basics of security and threading.After giving you a grounding in how DCOM works, this book introduces you to the Microsoft tools that make it all easy. By showing what really happens each time you choose a button in a wizard, Learning DCOM makes it possible for you to choose what you need.This book is for anyone who wants to understand DCOM. While thoroughly practical in its goals, it doesn't stint on the background you need to make your programs safe, efficient, and easy to maintain.Topics include:

  • MIDL (Microsoft Interface Definition Language, the language for defining COM interfaces)
  • COM error and exception handling
  • Custom, dispatch, and dual interfaces
  • Standard and custom factories
  • Management of in-process versus out-of-process servers
  • Distributed memory management
  • Pragmatic explanation of the DCOM wire protocol
  • Standard, custom, handler, and automation marshaling
  • Multithreading and apartments
  • Security at the system configuration and programming level
  • Active Template Library (ATL), ATL wizards -- and what they don't do
  • Writing a component that can be invoked from Visual Basic
  • Techniques for using distributed components
  • Creating an ActiveX control and embedding it in a Web client
  • Authentication and the use of Windows NT security features
  • Techniques for merging marshaling code
  • Connection and distributed events management
  • An introduction to COM+ features

Table of Contents

  1. Learning DCOM
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Preface
    1. Scope of This Book
    2. Some Assumptions About the Reader
    3. Accompanying Source Code
      1. FTP
      2. FTPMAIL
    4. Conventions
    5. Related Sources of Information
      1. Specifications and References
      2. The Classics
      3. Knowledge Base Articles
      4. Technical Articles
      5. Other Related Documentation
    6. Acknowledgments
  5. 1. Distributed Computing
    1. Dumb Terminals
    2. Client/Server Computing
    3. Distributed Computing Using RPC
    4. Distributed Objects
    5. Distributed Components
  6. 2. Distributed COM Overview
    1. COM
      1. The Object-Oriented Model
        1. Encapsulation
        2. Inheritance
        3. Polymorphism
      2. The Client/Server Model
    2. Distributed COM
    3. COM Facilities and Services
      1. Location Transparency
      2. Dynamic and Remote Object Activation
      3. Security
      4. Interfaces
      5. Lifetime Support and Dynamic Discovery
      6. Binary Interoperability
      7. Connection Management
      8. Concurrency Management
      9. Reuse
      10. Interface Repository
      11. Implementation Repository
      12. Static Invocation
      13. Dynamic Invocation
      14. Events
    4. Applying COM
  7. 3. Objects
    1. Interfaces
      1. IUnknown
      2. Microsoft Interface Definition Language
        1. MIDL basics
        2. Defining a custom interface using MIDL
        3. Examining the attributes of IUnknown
        4. Arrays and strings as interface method parameters
        5. Custom types as interface method parameters
        6. Adding more custom interfaces
        7. Defining a type library
        8. Published interfaces must never change
      3. Return Values
        1. HRESULT
        2. Custom HRESULTs
      4. Data Types
        1. Base data types
        2. Automation compatible types
      5. Interface Marshalers: Proxy and Stub
      6. The Binary Layout
      7. Dispatch and Dual Interfaces
      8. An Interface Recap
    2. Objects
      1. Implementing Interfaces
      2. IUnknown Rules
        1. Identity rules
        2. Existence rules
      3. Implementing COM Objects
        1. COM object definition using the nested classes technique
        2. COM object definition using the multiple inheritance technique
        3. Implementing IUnknown methods
        4. Implementing other interface methods
    3. Class Factories
      1. Standard Factories
      2. Custom Factories
  8. 4. Components
    1. Servers
      1. Server Types
        1. Out-of-process servers
        2. In-process servers
      2. Initialization and Termination
        1. Out-of-process servers
        2. In-process servers
      3. Dynamic Activation Support
        1. Out-of-process servers
        2. In-process servers
      4. Component Lifetime
        1. Out-of-process servers
        2. In-process servers
      5. Implementation Registration
        1. Out-of-process servers
        2. In-process servers
        3. Registering interface marshalers
    2. Clients
      1. Initialization and Termination
      2. Creating an Object
        1. CoCreateInstance
        2. CoCreateInstanceEx
        3. CoGetClassObject
        4. Class monikers
      3. Initializing an Object
      4. Using an Object
      5. Deleting an Object
      6. In- and Out-of-Process Issues
    3. Object Orientation
      1. Encapsulation
      2. Polymorphism
      3. Reuse
      4. Containment
      5. Aggregation
        1. Using objects that support aggregation
        2. Developing objects that support aggregation
  9. 5. Infrastructure
    1. Memory
      1. Simple Data Types and Top-Level Pointers
      2. Secondary and Embedded Pointers
        1. COM API functions for distributed memory management
        2. Managing embedded pointers
      3. Character Pointers
      4. Automation Data Types
        1. Memory management for a BSTR
        2. Memory management for a SAFEARRAY
    2. Transparency
      1. Structure of a Marshaled Interface Reference
      2. Activation
      3. Standard Marshaling
        1. More on activation
        2. Remote invocation
      4. Custom Marshaling
        1. The object’s responsibility
        2. The custom proxy’s responsibility
      5. Handler Marshaling
      6. Automation Marshaling
      7. Remote Connection Management
    3. Concurrency
      1. Single-Threaded Apartment
        1. Basic requirements
        2. Synchronization
        3. Other issues
      2. Sharing Interface Pointers Among Apartments
      3. Multithreaded Apartment
        1. Basic requirements
        2. Synchronization
        3. Other issues
      4. Out-of-Process Server Considerations
      5. In-Process Server Considerations
        1. ThreadingModel=“” (default)
        2. ThreadingModel=“Apartment”
        3. ThreadingModel=“Free”
        4. ThreadingModel=“Both”
        5. Free-Threaded Marshaler
      6. Performance
    4. Security
      1. Configurable Security
        1. Machine-wide security
        2. Application-wide security
        3. Application identity
      2. Programmable Security
        1. General application-wide security on both the client and server side
        2. Access security on the server side
        3. Activation security on the client side
        4. Call-level security on the client side
        5. Using the security context on the server side
  10. 6. Building Components with ATL
    1. Creating a Component
    2. Adding an Object
    3. The Generated Code
      1. Generated Interface
      2. Generated Implementation
    4. Common Responsibilities
      1. Implementing Interface Methods
      2. Adding a Custom Interface
      3. Adding Another Dual Interface
    5. Finishing Up
  11. 7. Using COM Objects
    1. Simple Client
      1. Initializing and Uninitializing COM
      2. Creating the User Interface
    2. The COleDispatchDriver Technique
      1. Creating an Interface Wrapper Class
      2. The COleDispatchDriver Class
      3. Using COM Interfaces with Generated Wrappers
    3. The #import Technique
      1. The #import Statement
      2. Using COM Interfaces with Smart Pointers
      3. Native C++ Compiler Features
        1. More on smart pointers
        2. Exception handling
    4. The Manual Technique
      1. Remote Activation API Functions
      2. Using COM Interfaces Manually
    5. The Reusable echnique
      1. The RemotePtr Class
      2. Using the RemotePtr Class
    6. Review
  12. 8. COM in Cyberspace
    1. ATL ActiveX Controls
      1. Creating the Project
      2. Adding an ActiveX Control
      3. Merging the Proxy/Stub Code
      4. Adding Properties
      5. Adding Methods
        1. Step 1: Merging the proxy/stub code for external (remote) interfaces
        2. Step 2: Reusing the RemotePtr class
        3. Step 3: Coding the OcrImage method
    2. Web-Enabled Clients
      1. Control Buttons
      2. Server Name and Image Location
      3. Wang Image Edit ActiveX Control
      4. OCR Results
      5. ATLCyberOcr ActiveX Control
      6. Complete HTML and VBScript Source Code
      7. Problems with COM over the Internet
        1. Problems with security
        2. Problems with firewalls or proxy servers
    3. MFC Composites
      1. Creating an MFC ActiveX Control Project
        1. Understanding the generated code
        2. Creating the user interface
        3. Using an ActiveX control within an ActiveX control
        4. Implementing the ActiveX Control: CMFCCyberServerCtrl
        5. CMFCCyberServerCtrl::OnCreate
        6. CMFCCyberServerCtrl::OnDraw
      2. Implementing CImagingWindow
        1. CImagingWindow::OnCreate
        2. CImagingWindow::OnSize
        3. Handling command messages
    4. ATL Composites
      1. Creating the Project
      2. Adding a Composite Control
      3. Creating the User Interface
        1. Putting common controls onto the composite
        2. Putting ActiveX controls onto the composite
        3. Testing the user interface
      4. Implementation
        1. Importing the embedded ActiveX control
        2. Adding command handlers in ATL
        3. Testing the final product
    5. ActiveX Control Properties
      1. Playing with Property Pages
        1. Step 1: Creating the application
        2. Step 2: Adding the two views
        3. Step 3: Adding a splitter window
        4. Step 4: Putting the two ActiveX controls on their appropriate views
        5. Step 5: Showing the property pages
      2. Adding a Property to CMFCCyberServerCtrl
  13. 9. Applying Security
    1. Server-Side COM Security
      1. Creating the Project and a COM Object
      2. Implementing the SecureOcrImage Method
      3. Validating the Invocation
    2. Access Token
      1. Constructor and Destructor
      2. Getting the Access Token
      3. Getting User Information
      4. Getting Group Information
    3. Audit Trail
      1. Creating Message Files
        1. Creating a message file for your component
        2. Compiling a message file
      2. Updating the Registry with Event Source Information
      3. Logging Messages
    4. Administrative Alert
      1. Administrative Alert Setup
      2. Generating an Administrative Alert
    5. Client-Side Security
      1. Setting the Authentication Identity
      2. Setting the Process-Wide Security
      3. Merging Proxy/Stub Code into a Client EXE Component
      4. Using Activation Security
      5. Using Call Security
      6. Handling Errors
      7. Testing and Understanding COM Security
        1. Test Scenario I—Observing call-level security and logged events
        2. Test Scenario II—Observing administrative alerts
        3. Test Scenario III—Observing activation security
  14. 10. Connecting Objects
    1. Object Reference
    2. Referrers
      1. Creating the ChatBroker Component
      2. Adding a Broker COM Object
        1. The IRegisterChatServer interface
        2. The IDiscussions interface
      3. Caching a List of Discussions
        1. CChatDiscussionList::AddDiscussion
        2. CChatDiscussionList::RemoveDiscussion
        3. CChatDiscussionList::GetDiscussionList
        4. CChatDiscussionList::GetChatServer
        5. CChatDiscussionList::GetSize
        6. ChatBroker’s special condition for component lifetime management
      4. Implementing the Interface Methods
      5. Merging Proxy/Stub Code into a Server EXE Component
    3. Connection Points
    4. Event Sources
      1. Creating an Event Source Object
      2. Adding a Connection Point
        1. Step 1: Define a callback interface using MIDL
        2. Step 2: Implement a connection point object
        3. Step 3: Add a connection point to the event source object
      3. Receiving and Disseminating a Chat Message
      4. The Responsibility of the ChatServer Application
        1. Handling of command-line options
        2. Registering interface marshalers
        3. Opening and closing the discussion
      5. Running the ChatServer
    5. Event Sinks
      1. Creating the ChatClient Project
        1. Creating the user interface and adding command handlers
        2. Merging proxy/stub code into a project without an IDL File
      2. Connecting to and Disconnecting from a ChatBroker
      3. Joining and Leaving a Chat Discussion
      4. Sending a Chat Message
      5. Receiving Chat Messages
    6. Performance Impact of Connection Points
    7. Security Impact of the OBJREF
  15. A. Debugging Techniques
    1. Using the FormatMessage Function
    2. Using the _com_error Class
    3. Breaking into the Server
  16. B. Performance
    1. Performance Results for ThreadingModel=“”
    2. Performance Results for ThreadingModel=“Apartment”
    3. Performance Results for ThreadingModel=“Free”
    4. Performance Results for ThreadingModel=“Both”
  17. C. New COM Features and COM+
    1. Endpoint Configuration
    2. Nonblocking Calls
    3. COM+
      1. Runtime that Simplifies Component Development and Usage
        1. Hide nonbusiness logic complexities
        2. Simplify component development and usage
      2. Services that Support Large-Scale Enterprise Needs
  18. D. Hello, Universe!
    1. Client/Server Protocol = COM Interface
    2. Client Component
    3. Server Component
      1. The main( ) routine
      2. The Class Factory
      3. The COM Object
    4. Comforting Words
  19. Index
  20. Colophon
  21. Copyright