COM Programming with Microsoft® .NET

Book description

Providing both theoretical and practical approaches, this in-depth programming guide explains how to interoperate between COM/COM+ and Microsoft® .NET. Coverage includes writing COM and COM+ code, disconnected applications, and new technologies in .NET.

Table of contents

  1. COM Programming with Microsoft® .NET
  2. A Note Regarding Supplemental Files
  3. Acknowledgments
  4. Introduction
    1. What’s in This Book
    2. Who Is the Audience for This Book?
    3. Companion Content
    4. What You Need
    5. Equipment Used
      1. Workstation Setup
      2. Server Setup
    6. Reader Aids
    7. Microsoft Press Support
  5. I. The .NET View of COM and COM+
    1. 1. COM and .NET
      1. Is COM Dead?
      2. How Does COM Work in the .NET World?
      3. Differences in the COM and .NET Philosophies
        1. Locating Components
        2. Component Identification
        3. Object Lifetimes
        4. Determining Object Capabilities
        5. Constructors and Destructors
        6. Nondeterministic Finalization
        7. Error Handling
        8. Type Information
        9. Visibility
        10. Data Handling
          1. Using .NET Servers with COM Clients
          2. Using COM Servers with .NET Clients
          3. Interop Marshaling
          4. Marshaling Structures
          5. The Marshal Class
        11. Event Handling
      4. Using the IDE to Access Components
        1. Locating the Component You Need
          1. Locating COM Components
          2. Locating UI Components
        2. Simple COM Access Examples
          1. Using a COM Component
          2. Using an ActiveX Control
      5. Summary
    2. 2. COM+ and .NET
      1. What Is the Place of COM+ in the .NET World?
      2. COM+ Problems and Improvements
      3. Using the Component Services MMC Snap-In
        1. An Overview of the Interface
        2. Creating COM+ Applications and Installing Components
          1. Creating the COM+ Application
          2. Adding Components to a COM+ Application
          3. Adding Security to a COM+ Application
          4. Exporting COM+ Applications
      4. Using the .NET Framework Configuration MMC Console
        1. Managing Components and Controls
        2. Remoting Services Configuration
        3. Defining a Runtime Security Policy
      5. Summary
    3. 3. Using COM Components in .NET Code
      1. COM Interop: Principles and Mechanisms
        1. Interop Assemblies
        2. Primary Interop Assemblies
      2. Generating Runtime Callable Wrappers
        1. Using Visual Studio .NET
        2. Using the TlbImp.exe Tool
          1. Simple Use of TlbImp.exe
          2. Using TlbImp.exe Options
          3. Namespaces
          4. Resolving References
          5. The /transform:dispret Option
        3. Using the TypeLibConverter Class
        4. Assemblies and the GAC
          1. Strong Names
          2. Signing Assemblies
          3. Installing Assemblies into the GAC
          4. Delayed Signing
        5. Generating and Installing Primary Interop Assemblies
      3. How COM Entities Are Converted
        1. Dealing with Attributes
        2. Importing Libraries
        3. Importing Data Types
          1. Handling void* Arguments
          2. Using IntPtr from Visual C#
          3. Converting Arrays
        4. Importing Classes
          1. Implementing Multiple Interfaces
        5. Importing Interfaces
          1. Importing Methods
          2. Importing Properties
        6. Importing Structures, Unions, and Enumerations
          1. Structures
          2. Unions
          3. Enumerations
          4. Constants
        7. Importing Typedefs
        8. Importing Modules
      4. How to Design COM Components for Use with .NET
      5. Responding to COM Events
        1. Connection Points
        2. Handling Events from a COM Source
          1. Events Example
      6. Using ActiveX Controls with .NET
        1. Adding an ActiveX Control to the Toolbox
        2. Using the Command Line
      7. Summary
    4. 4. Using .NET Components in COM Applications
      1. The COM Callable Wrapper
        1. Object Identity
        2. Object Lifetime
        3. Standard COM Interfaces on .NET Components
        4. Custom Interfaces on .NET Components
          1. The Class Interface
          2. Problems with Using the Class Interface
      2. Generating and Using COM Callable Wrappers
        1. Using COM-Related Attributes
          1. The ClassInterface Attribute
          2. The InterfaceType Attribute
          3. The Guid and ProgId Attributes
          4. The ComVisible Attribute
          5. The AutomationProxy Attribute
          6. The IDispatchImpl Attribute
          7. The ComRegisterFunction and ComUnregisterFunction Attributes
        2. Creating a Type Library
          1. Command-Line Tools
          2. Using TypeLibConverter
        3. Signing the Assembly
        4. Registering the Component
        5. Using .NET Components from COM Client Code
          1. The Sample Component
          2. Installing the Component for COM Use
          3. Looking at the Type Library
          4. Using the Class in COM Code
      3. Exporting Metadata to Type Libraries
        1. Exporting Assemblies
        2. Exporting Namespaces
        3. Exporting Classes
        4. Exporting Interfaces
          1. Choosing Interface Types
          2. Interfaces and Inheritance
          3. Exporting Methods
          4. Exporting Properties
        5. Exporting Data Types
        6. Exporting Value Types
        7. Exporting Enumerations
      4. How to Design .NET Components for Use with COM
        1. Provide a Default Constructor
        2. Avoid Using Static and Overloaded Methods
        3. Be Aware of Possible Naming Problems
          1. Assembly Naming
          2. Method-Naming Conflicts
        4. Avoid Altering Interfaces
        5. Define Event Source Interfaces
        6. Use of Attributes
        7. Provide HRESULTs
        8. Use Versioning Correctly
      5. Hosting Windows Forms Controls in ActiveX Control Containers
        1. Registry Entries
          1. Identifying a Control
          2. Type Library Entries
          3. Miscellaneous Entries
        2. Example: Hosting a Windows Forms Control in Internet Explorer
      6. Exposing .NET Events in COM
        1. Using Explicit Source Interfaces
          1. Consuming Events in Visual Basic 6
      7. Summary
    5. 5. An Overview of COM+ Coding for .NET
      1. COM+ Begins with COM
        1. A Look at COM+ Interoperability
        2. COM+ Design Goals
        3. Transactions and COM+
        4. Messages and COM+
        5. COM+ Services
      2. Understanding the Role of DCOM in COM+
        1. How Does the Connection Work?
        2. Connection-Oriented Data Flow Optimization
      3. COM+-Specific Issues
        1. Application Types
          1. Server Applications
          2. Library Applications
          3. Proxy Applications
          4. Preinstalled Applications
        2. Error Handling
        3. Security
      4. Summary
  6. II. Writing COM Code
    1. 6. Attributed Programming
      1. What Are Attributes?
        1. How Do Attributes Work?
      2. Using Attributes in C++ Code
      3. Walkthrough: Creating a Simple COM Component
        1. Seeing the Inserted Code
        2. Adding COM Objects
          1. What About IDL?
        3. Adding Methods and Properties
        4. Testing the Component
        5. Creating the Server by Hand
          1. Creating the Header File
          2. Creating the ATL DLL
          3. Adding Interface and Coclass Definitions
      4. Basic Attributed Programming
        1. Creating Modules
          1. Using the module Attribute
          2. The custom Attribute
        2. Creating Interfaces
          1. Defining Interface Methods
          2. Dispatch Interfaces
          3. Handling Arrays
        3. Creating Coclasses
          1. Default Interfaces
        4. Stand-Alone Attributes
          1. The emitidl Attribute
      5. Handling Aggregation
        1. Review of COM Aggregation and Delegation
        2. The aggregatable and aggregates Attributes
      6. Handling Errors
      7. Events
        1. Adding Event Support
          1. Manually Writing COM Event Code
        2. Handling Events
      8. Compiler Options
        1. Generating IDL
        2. Suppressing IDL Generation
      9. Summary
    2. 7. ATL and ATL Server
      1. Changes in ATL 7.0
        1. New Module Classes
        2. Data Handling and Collections
          1. Classes for Managing Lists, Arrays, and Trees
          2. The CSimpleArray Class
          3. The CAtlArray Class
          4. Support for SAFEARRAYs
          5. Support for Collections and Enumerators
        3. Shared Classes
        4. The CSimpleStringT Class
          1. Memory Management
          2. CSimpleStringT Example
        5. The CStringT Class
          1. Predefined Types for Use with CStringT
          2. CStringT Example
        6. String Conversion Classes
        7. Security Classes
        8. Regular Expression Classes
        9. Other Changes
        10. Breaking Changes Since Visual C++ 6.0
      2. Introduction to ATL Server
      3. ATL Server Architecture
        1. ISAPI Extensions
        2. Web Application DLLs
        3. Server Response Files
          1. SRF Syntax
          2. Handler and Subhandler Tags
          3. Including Files
          4. Defining Replacement Tags
      4. Writing Web Applications Using ATL Server
        1. Using Attributes
          1. The request_handler Attribute
          2. The tag_name Attribute
        2. Defining Handler Methods
          1. Using Parsing Functions
        3. A Sample ATL Server Application
          1. Creating the Project
          2. Handling Simple Arguments
          3. Implementing Custom Parsing
      5. Writing Web Services Using ATL Server
        1. ATL Server Web Service Architecture
          1. SOAP and Web Services
          2. Implementing Web Services
        2. Example: Creating a Web Service
      6. Consuming Web Services in C++
      7. Summary
  7. III. Writing COM+ Code
    1. 8. A Simple COM+ Example
      1. The Importance of Using GUIDs
      2. A Simple Component Example
        1. Creating the Simple Component
        2. Registering the Component on the Server
          1. Using the GUI Method
          2. Using the RegSvcs Utility
        3. Exporting the Application
        4. Creating the Client
        5. Testing the Application
        6. A Component Class Example
        7. Deriving from the Component Class
        8. Performing the Component Class Setup
        9. Creating the Client
      3. A ServicedComponent Class Example
        1. Deriving from the ServicedComponent Class
        2. Performing the ServicedComponent Class Setup
        3. Creating the Client
      4. Summary
    2. 9. Working with Disconnected Applications
      1. Understanding the Role of MSMQ in this Application
      2. Creating a Simple Recorder/Player
        1. Defining the Message Queue
        2. Accessing the Message Queue
        3. Creating the Recorder
        4. Testing the Recorder
        5. Creating the Player
      3. Creating a Simple COM+ Listener/Player
        1. Creating the Listener/Player Component
        2. Defining the MSMQ Rule and Trigger
        3. Testing the Listener/Player Application
      4. Creating the MSMQ Client Application
        1. Designing the Data Encapsulation Component
        2. Designing the Message Queue Component
        3. Installing the Message Queue Component
        4. Designing a Managed Client
        5. Testing the Application
      5. Summary
    3. 10. Creating Subscriptions
      1. An Overview of the COM+ Catalog
      2. What Are Subscriptions?
        1. Understanding Transient Subscriptions
        2. Understanding Permanent Subscriptions
        3. Understanding the Need for Dynamic Registration
      3. Creating the Event Object
        1. Designing the Component
        2. Installing the Event Object
      4. Creating the Publisher
      5. Creating a Component Subscriber
        1. Designing the Subscriber Component
        2. Installing and Testing the Subscriber Component
      6. Creating a Dialog-Based Subscriber
        1. Creating a Permanent Subscription
        2. Testing the Permanent Subscription
        3. Creating a Transient Subscription
        4. Testing the Transient Subscription
      7. Summary
    4. 11. Web Application Scenarios
      1. How Do Web-Based Applications Differ?
        1. COM+ 1.5 and SOAP
        2. COM+ 1.5 and Application Dumps
        3. Component Interactions
        4. Scripting Error Handling
        5. Human-Language Support
        6. Accessibility Concerns
        7. ASP and Component Communication
      2. Defining the Database
      3. Creating the Data Access Component
      4. Using ASP to Access the Database
      5. Testing the Application
      6. Summary
  8. IV. Interoperability
    1. 12. Interacting with Unmanaged Code
      1. Managed and Unmanaged Code
        1. Manual and Automatic Memory Management
        2. Interoperating Between Managed and Unmanaged Code
        3. Garbage Collection in .NET
          1. Generations
          2. The Large Object Heap
          3. Roots
          4. Finalization
      2. Platform Invoke
        1. Using Platform Invoke from Visual Basic .NET
          1. Using the Declare Statement
          2. Using DllImport
          3. Specifying an Entry Point
          4. The CharSet and ExactSpelling Parameters
          5. The PreserveSig Parameter
          6. Handling Errors
        2. Converting Windows API Parameter Types
        3. Using Platform Invoke from Visual C#
        4. Using Platform Invoke from Managed C++
      3. Visual C# Concerns
        1. The unsafe Keyword
        2. The fixed Keyword
        3. The stackalloc Keyword
      4. Visual C++ Concerns
        1. Marshaling Argument Types
        2. Pinning
        3. Calling Exported C++ Member Functions
        4. IJW (It Just Works)
        5. IJW vs. P/Invoke
      5. Summary
    2. 13. Advanced Interaction
      1. The MarshalAs Attribute
      2. Marshaling Strings
        1. String and StringBuilder
      3. Marshaling Structs
        1. The StructLayout Attribute
          1. Explicit Layout
        2. Handling Nested Structures
      4. Marshaling Arrays
        1. Marshaling Arrays in Platform Invoke
          1. Passing Arrays by Value
          2. Passing Arrays by Reference
          3. Marshaling Arrays in Structures
          4. Marshaling Arrays of Structures
        2. Marshaling Arrays in COM Interop
          1. Passing Arrays to COM
      5. Passing Managed Pointers to Unmanaged Code
        1. Pinning in Managed C++
        2. Using gcroot in Managed C++
      6. Dynamically Loading Platform Invoke DLLs
        1. Choosing the Path to the DLL at Run Time
          1. Fully Dynamic DLL Loading
      7. Using Callbacks
        1. Introduction to Delegates
        2. Using Delegates for Callbacks
      8. Garbage Collection Considerations
        1. Using the KeepAlive Method
        2. Using the HandleRef Type
      9. Performance Considerations
      10. Summary
    3. 14. Working with Predefined Interfaces
      1. COM Requires Specific Interfaces
      2. Using the OLE/COM Object Viewer
        1. A Quick Overview of Interfaces
        2. Viewing the .NET Category
        3. Viewing an Unmanaged Control
        4. Performing Interface Analysis
      3. Re-creating COM Interfaces Using Managed Code
      4. Creating a Component with Specialized Interfaces Example
      5. Summary
  9. About the Author
  10. Air Compressor
  11. Index
  12. About the Authors
  13. Copyright

Product information

  • Title: COM Programming with Microsoft® .NET
  • Author(s):
  • Release date: February 2003
  • Publisher(s): Microsoft Press
  • ISBN: 9780735618756