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