Adding References to COM Libraries

In some situations you might be required to use COM-type libraries in your .NET applications, a scenario also known as COM Interop. This should be rare, though, because .NET and COM are very different architectures, and they were not made to work together. However, Visual Studio 2015 enables you to add references to old libraries. To accomplish this, you need to select the COM tab in the Reference Manager dialog box. All the registered COM-type libraries are shown in the dialog box, and you can select the needed components (see Figure 3.5).

Image

FIGURE 3.5 Adding a reference to a COM component.

For example, say that you want to include Windows Media Player functionalities in your application. To do this, you can select the Windows Media Player component and then click OK (see Figure 3.5). Visual Studio then shows a reference named WMPLib.dll in Solution Explorer and generates an assembly named Interop.WMPLib.dll. This assembly is a managed wrapper for the Windows Media Player component, and it provides managed access to types exposed by the type library.

More generally, Visual Studio generates an Interop.AssemblyName.dll assembly (where AssemblyName is the original name of the assembly) for each referenced type library. These are known as primary interoperability assemblies (PIAs), and they allow interoperation between .NET and COM architectures.

Unlike in previous versions of .NET Framework and Visual Studio, by default you no longer see the wrapper assemblies included in your build output because of a feature called Deploy Without PIAs, discussed next.

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

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