Chapter 20: COM Interoperability and ADO.NET


Overview

The component object Model (COM) has been around for many years and is used by many Windows applications. Eventually the .NET platform will replace COM, but until then you may need to develop COM components from .NET and access them from unmanaged code, or you may want to use COM components in .NET applications. COM interoperability (also referred to as COM Interop) enables you to use existing COM components in .NET applications or use .NET components in unmanaged code.

Note

In this chapter you'll see how to use ADO and other COM-based data access technologies through COM Interop in your .NET applications. However, COM interoperability is a wide area. If you want to learn about COM interoperability in more detail, you may want to read COM and .NET Interoperability by Andrew Troelsen (Apress, 2002).

The code written for the .NET Framework is also referred to as managed code, and the code written for traditional Windows applications (previous to the .NET Framework) is called unmanaged code. Managed code contains metadata used by the Common Language Runtime (CLR).

In COM, type libraries stored metadata for a COM component and described the characteristics of a COM component. In .NET, an assembly is the primary building block of a .NET application. An assembly is a collection of functionality that's built, versioned, and deployed as a component. An assembly contains an assembly manifest, which performs similar functions to a COM type library. The assembly manifest includes information about an assembly such as the identity, version, culture, digital signature, compile-time dependencies, files that make up the assembly implementation, and permissions required to run the assembly properly.

In brief, COM understands the language of type libraries, and the .NET Framework understands the language of assembly manifests. So converting a type library into an assembly manifest provides accessibility to COM components from the managed code, and converting an assembly manifest to a COM type library provides accessibility to .NET assemblies in unmanaged code.

Interop assemblies are .NET assemblies that act as a bridge between managed and unmanaged code. Interop assemblies provide mapping COM object members to equivalent .NET managed members.

The .NET Framework defines a common set of data types. All .NET programming languages use these common data types. During the import process of a COM type library, there may be cases when the parameters and return values of COM objects use data types that do not correspond to .NET data types. The Interop marshaler handles these conversions for you. Interoperability marshaling is the process of packaging parameters and returning values into equivalent data types during conversion of a COM type library to an assembly manifest and an assembly manifest to a COM type library.

Tip

If you're looking for more COM-and Interop-related answers, you may want to look at the System.Runtime.InteropServices namespace and its classes in the MSDN documentation.




Applied ADO. NET(c) Building Data-Driven Solutions
Applied ADO.NET: Building Data-Driven Solutions
ISBN: 1590590732
EAN: 2147483647
Year: 2006
Pages: 214

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