Summary

.NET supports interoperability with APIs in native DLLs as well as with COM components. The SDK defines a collection of classes under the namespace System.Runtime.InteropServices to support this interoperability.

The ability to access APIs in native DLLs is offered through a mechanism called PInvoke, which offers a great deal of support for marshaling basic datatypes, pointers, and even structures.

The default marshaling options used by the interop marshaler try to make interoperability as seamless as possible. In cases where there is an ambiguity on how a managed type can be marshaled, the .NET Framework defines a mechanism to let the developers provide marshaling hints to the interop marshaler.

The framework also defines a mechanism to invoke COM components from .NET applications and .NET components from COM applications. For accessing COM objects, the interop layer creates an RCW around the COM object and makes it appear as a .NET object to managed code. For accessing .NET objects, the interop layer creates a CCW around the .NET object and makes it appear as a COM object to the unmanaged code.

In a later chapter on enterprise services, we will look at how .NET preserves the context information across the .NET–COM interop layer. This makes it possible, for example, for .NET as well as COM components to participate in a transaction.

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

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