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 HARDWARE

PC that meets .NET SDK minimum requirements

SKILLS REQUIRED

C# and .NET familiarity

Familiarity with COM


COM AND WINDOWS INTEROPERABILITY AT A GLANCE

Using .NET Code to Interact with COM

275

  
 

Introduction to COM Interop

275

Code Interoperability Example: .NET Code Invoking COM Code

278

 

The Runtime Callable Wrapper

275

 

.NET to COM Marshalling

276

  

COM to .NET

281

  
 

The COM Callable Wrapper

281

Interop Programming Example: COM Code Utilizing NET Components

283

 

.NET Code Attributes for COM Interop Programming

281

 

When to Use Interop

285

 

Marshalling Data from COM to .NET

282

  

Primary Interop Assemblies

286

  
 

Overview of Primary Interop Assemblies

286

Working with PIAs

286

 

Producing and Deploying PIAs

287

Platform Invoke (P/Invoke)

288

  
 

Introduction to Platform Invoke

288

Platform Invoke SampleThe Win32 API

290

 

Consuming Unmanaged DLLs

288

 

Platform InvokeData Marshalling

289

When to Use Platform Invoke

292

Summary

292

  

Further Reading

292

  




    Visual C#. NET 2003 Unleashed
    Visual C#. NET 2003 Unleashed
    ISBN: 672326760
    EAN: N/A
    Year: 2003
    Pages: 316

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net