COM and .NET Interoperability / Edition 1

COM and .NET Interoperability / Edition 1

5.0 1
by Andrew Troelsen
     
 

ISBN-10: 1590590112

ISBN-13: 9781590590119

Pub. Date: 04/24/2002

Publisher: Apress

COM and .NET Interoperability provides a complete overview of the process of building .NET applications that interact (interoperate) with existing COM code. Before digging into that critical topic, author Andrew Troelsen offers a concise overview of the COM architecture and provides examples using various COM frameworks (C++, ATL, and VB 6.0

Overview

COM and .NET Interoperability provides a complete overview of the process of building .NET applications that interact (interoperate) with existing COM code. Before digging into that critical topic, author Andrew Troelsen offers a concise overview of the COM architecture and provides examples using various COM frameworks (C++, ATL, and VB 6.0) as well as the core .NET managed languages (C# and VB .NET).

After covering the preliminaries, the book explores numerous issues that arise in interoperability, including interacting with the Win32 API, dynamically generating source code via System.CodeDOM, creating serviced (COM+) components using managed code, manually editing (and recompiling) .NET metadata, and the process of constructing custom COM/.NET conversion utilities. Both intermediate and advanced developers will welcome the practical information they need to quickly work with COM and COM+ in .NET applications, and learn how to create .NET components that are COM compatible.

Product Details

ISBN-13:
9781590590119
Publisher:
Apress
Publication date:
04/24/2002
Series:
.NET Developer Series
Edition description:
2002
Pages:
816
Product dimensions:
7.52(w) x 9.25(h) x 0.07(d)

Table of Contents

Acknowledgmentsxxiii
Introductionxxv
Chapter 1Understanding Platform Invocation Services1
The Two Faces of Unmanaged Code1
Understanding the C-Style DLL2
Building a Custom C-Based DLL5
Viewing Your Imports and Exports Using dumpbin. exe9
Deploying Traditional DLLs12
A Dynamic C++ DLL Client15
The Atoms of PInvoke18
A Trivial PInvoke Example26
Interacting with MyCustomDLL.d1133
Working with Unmanaged Callbacks42
A Simple Callback Example43
A More Interesting Callback Function44
Building a C# Callback Client46
Summary49
Chapter 2The Anatomy of a COM Server51
Of Classes and Interfaces51
The Composition of a COM DLL63
The Role of Type Libraries65
The Role of the System Registry66
Creating the COM DLL Project Workspace67
Understanding COM Interfaces68
A Brief Word on COM-Centric Macros79
Implementing the ComCar80
Understanding IClassFactory84
Building Your Class Factory85
Implementing DLL Component Housing88
Exporting the Exports90
Registering the COM Server91
Developing a C++ COM Client97
Understanding COM Properties105
Building Scriptable Objects (Using IDispatch)108
The VARIANT Data Type112
A C++ IDispatch Example116
A Visual Basic IDispatch Client117
Understanding the Dual Interface118
Defining a Scriptable Object118
Building the Class Factory123
Updating DllGetClassObject123
Updating the Server's Registration File124
Building a VBScript Late-Bound Client124
Summary126
Chapter 3A Primer on COM Programming Frameworks127
The Role of the Active Template Library127
The Role of Visual Basic 6.0146
Summary159
Chapter 4COM Type Information161
The Format of a COM IDL File162
Defining COM Types163
Primitive COM Data Types164
IDL Method Parameter Attributes167
Defining COM Interface Types in IDL171
The ITypeInfo Interface185
Generating COM Type Information Programmatically189
Building the Type Library (ICreateTypeLib)191
Creating the IHello Interface193
Building the SayHello() Method198
Building the Hello Coclass200
Testing the Application201
Programmatically Reading COM Type Information203
Defining Custom IDL Attributes212
Introducing the System.Runtime.InteropServices Namespace218
Building a C# COM Type Information Viewer220
Summary228
Chapter 5The Anatomy of a .NET Server229
The Philosophy of .NET230
The Building Blocks of .NET231
Working with Managed Languages232
The Composition of a .NET Binary233
Building a C# Code Library235
Introducing ILDasm.exe243
Building a Managed Client250
Specifying Arbitrary Assembly Locations253
Understanding the Shared Assembly254
Using the Shared Assembly262
Versioning Shared Assemblies264
Working with Publisher Policy Assemblies267
And Now for Something Completely Different: System.CodeDOM270
Introducing the System.CodeDOM Namespace272
Compiling the Assembly284
Summary288
Chapter 6.NET Types289
The Role of System.Object289
Examining the .NET Data Type System294
The Set of Custom .NET Types297
Building a Complex Code Library302
Understanding Reflection304
Working with System.Type304
The System.Reflection Namespace309
Dynamically Loading an Assembly310
Building a Custom .NET Type Viewer312
A Brief Word Regarding System.Reflection.Emit323
Understanding .NET Attributes323
Creating and Applying Custom Attributes325
Reading Attributes at Runtime330
Binding Late to Shared Assemblies335
Summary338
Chapter 7.NET-to-COM Interoperability--The Basics339
A High-Level Overview of .NET-to-COM Interoperability339
Building an Interop Assembly--The Simplest Possible Example342
Converting Between COM IDL Data Types and Managed Data Types346
Interfaces Consumed by the RCW351
Options to Obtain an Interop Assembly353
Examining the Generated .NET Types356
Select Members of the System.Runtime.InteropServices Namespace362
COM Library Statement to .NET Assembly Statement Conversion Rules367
COM Types to .NET Types Conversion Rules371
Deploying Interop Assemblies392
Creating a Primary Interop Assembly393
Reflecting on Interop Assembly Attributes396
Interacting with Well-known COM Servers399
Summary402
Chapter 8.NET-to-COM Interoperability--Intermediate Topics403
Handling the COM VARIANT403
Building a VARIANT-Centric COM Server405
Handling COM SafeArrays410
Handling C-Style Arrays419
Handling COM Param Arrays420
Handling COM Structures421
Handling COM Collections426
A Brief Review of COM Connection Points (COM Events)437
Building a Connectable COM Type441
A Brief Review of .NET Delegates443
A Brief Review of .NET Events445
Examining the Interop Assembly448
Handling COM Error Objects459
The .NET Error Handling Mechanism464
Debugging COM Servers Using VS .NET468
Summary470
Chapter 9.NET-to-COM Interoperability--Advanced Topics471
Revisiting the Marshal Class471
COM Coclasses Implementing .NET Interfaces475
Guidelines for Building .NET Type Compatible COM Classes484
Consuming ActiveX Controls from Managed Code490
Options for Consuming ActiveX Controls from Managed Code495
Modifying the Code for the AxHost-Derived Type504
Manually Modifying Interop Assemblies508
Understanding the Interop Editing Process510
Dissecting the Layout of Attribute Metadata517
Building a "Scratch" Assembly519
Building the Managed Client526
Building a Custom Type Library Importer Utility528
Building the Main Shell530
Summary538
Chapter 10COM-to-.NET Interoperability--The Basics539
The Role of the CCW539
Core Requirements for COM-to-.NET Communications544
Using the tlbexp.exe Utility546
General Guidelines for Building COM-Aware .NET Types547
Critical .NET-to-COM Conversion Details554
Understanding the Class Interface557
Understanding the Object Interface562
The Case Against Class Interfaces563
Exposing Custom .NET Interfaces to COM564
Implementing Explicit Interfaces567
Controlling the Generated ProgID567
Controlling the COM Library Definition568
Handling Overloaded Methods569
Importing mscorlib.tlb570
Using the regasm.exe Utility572
Examining the Updated Entries574
Deploying the .NET Assembly582
Leveraging the Visual Studio .NET IDE584
Building a Visual Basic 6.0 COM Client584
Building a C++ COM Client589
Building a VBScript COM Client590
Summary591
Chapter 11COM-to-.NET Interoperability--Intermediate Topics593
Converting .NET Enums to COM Enums593
Converting .NET Structures to COM Structures598
Converting .NET Delegates to COM Connection Points604
Building a .NET Event Server Using VB .NET608
Building a Visual Basic 6.0 Event Client609
Building a C++ Event Client610
Exposing Custom .NET Collections614
Exposing .NET Exceptions619
Exercising Your DotNetCollection Assembly from C++621
Converting .NET Interface with Multiple Base Interfaces624
Converting .NET Interface Hierarchies627
Summary630
Chapter 12COM-to-.NET Interoperability--Advanced Topics633
Changing Type Marshaling Using MarshalAsAttribute633
.NET Types Implementing COM Interfaces638
Defining Custom COM Interfaces638
Building a VB 6.0 COM Client644
Defining COM Interfaces Using Managed Code646
Manually Defining COM Atoms: An Extended Example650
Interacting with Interop Assembly Registration653
Programmatically Converting Assemblies to COM Type Information655
Hosting the .NET Runtime from an Unmanaged Environment660
Summary667
Chapter 13Building Serviced Components (COM+ Interop)669
The MTS, COM+, Component Services Name Game669
Recapping Component Services670
Reviewing the COM+ Runtime Environment672
The Role of the COM+ Catalog675
The Component Service Explorer678
A Classic COM+ Example682
Building a VB 6.0 COM+ Client683
Deploying COM+ Applications685
The System.EnterpriseServices Namespace687
The Simplest Possible Example690
Using the regsvcs.exe Command Line Utility694
Accessing the Configured .NET Component from VB 6.0698
Accessing the Configured .NET Component from C#699
Enabling Component Statistics699
A Brief Word on Lazy (Automatic) Registration700
Working with the RegistrationHelper Type701
Configuring a Managed COM+ Application Using .NET Attributes703
Supporting Object Construction Strings704
Examining the ContextUtil Type706
Understanding JITA708
JITA, IObjectControl, and the .NET Garbage Collector714
Configuring Poolable Objects715
A Recap of Transactional Programming717
Programming COM+ Transactions720
A Complete Serviced Component Example724
Final Thoughts Regarding System, EnterpriseServices736
Summary738
Index739

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >

COM and .NET Interoperability 5 out of 5 based on 0 ratings. 1 reviews.
Guest More than 1 year ago
If you are a COM developer and are wanting to move to .NET then this book is an essential read.