Chapter 13. COM and Windows Interoperability

IN BRIEF

Anyone who has ever done a significant amount of work with COM (Component Object Model) knows that the intentions of the standard were great, but the implementation fell short of the desired solution.

The goal of COM was to create a solution that would enable developers to create separate, self-contained components that could then be employed by developers using different programming languages in other environments. The actual solution did indeed provide that framework, but that framework has many limitations. The .NET Framework removes quite a few of those limitations.

It would be extremely easy for us to assume that COM is dead and that we don't need to concern ourselves with it. Unfortunately, COM is still alive and kicking, and must be dealt with whether we like it or not. A considerably large number of COM objects are still active and in use, so one goal of this chapter is to show you how to interact with those COM components.

In addition to interacting with COM, you must be able to interact with the underlying operating system as well as other DLLs that are not COM libraries (yes, they do actually exist). This chapter will take you through an examination of OS and DLL interoperability through a feature of .NET called platform invoke.

The topic of COM interoperability is one that can consume a book on its own. The information contained in this chapter should be enough to get you going, but will skip some of the low-level implementation details to avoid bogging you down and diluting the big picture.

WHAT YOU NEED

RECOMMENDED SOFTWARE.NET Framework SDK v1.1

Visual Studio .NET 2003 with C# installed

Visual Basic 6.0 (for COM Interop)
RECOMMENDED HARDWAREPC that meets .NET SDK minimum requirements
SKILLS REQUIREDC# and .NET familiarity Familiarity with COM

COM AND WINDOWS INTEROPERABILITY AT A GLANCE

Using .NET Code to Interact with COM275  
 Introduction to COM Interop275Code Interoperability Example: .NET Code Invoking COM Code278
 The Runtime Callable Wrapper275
 .NET to COM Marshalling276  
COM to .NET281  
 The COM Callable Wrapper281Interop Programming Example: COM Code Utilizing NET Components283
 .NET Code Attributes for COM Interop Programming281
 When to Use Interop285
 Marshalling Data from COM to .NET282  
Primary Interop Assemblies286  
 Overview of Primary Interop Assemblies286Working with PIAs286
 Producing and Deploying PIAs287
Platform Invoke (P/Invoke)288  
 Introduction to Platform Invoke288Platform Invoke Sample—The Win32 API290
 Consuming Unmanaged DLLs288
 Platform Invoke—Data Marshalling289When to Use Platform Invoke292
Summary292  
Further Reading292  

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.154.64