Where COM Interop Comes into Play

Where COM Interop Comes into Play

There are three common situations in which you will encounter COM interop: when using ActiveX controls, when calling a COM component from a .NET application or component, and when calling a .NET component from a COM application or component. Let s take a look at each of these situations.

ActiveX Controls

Visual Basic .NET allows you to place either .NET or ActiveX controls on a Windows form. Chapter 13covers ActiveX control hosting in more detail. Suffice it to say that the way you use ActiveX controls in Visual Basic .NET is nearly identical to the way you use them in Visual Basic 6. You add the control to the Toolbox, place the control on the form, set design-time property values, and then write code behind it. No sweat.

Communication Between a .NET Client and a COM Server Component

The .NET Framework enables .NET clients to communicate with COM components. It accomplishes this by wrapping the COM component in a runtime callable wrapper (RCW) to make it look like a .NET component, as illustrated in Figure 9-1. Exposing a COM component for use with .NET requires no additional work. You simply add the COM component as a reference, and Visual Studio .NET takes care of generating the RCW for you. Later in this chapter, we demonstrate how to call a COM server from a .NET Web application.

Figure 9-1

Runtime callable wrapper that enables a COM component to look like a .NET component.

Communication Between a COM Client and a .NET Server Component

In addition to allowing .NET clients to communicate with COM components, the .NET Framework allows COM applications to communicate with .NET components by making a .NET component look like a COM component. It accomplishes this by creating a wrapper around the .NET component called a COM callable wrapper (CCW), as illustrated in Figure 9-2. To expose a .NET component to COM, you must register your .NET component as being COM callable. Visual Studio .NET provides a way for .NET components to be registered automatically for COM. The next section demonstrates how to upgrade a Visual Basic 6 component to .NET and then expose that .NET component to COM.

Figure 9-2

COM callable wrapper that enables a .NET component to look like a COM component.



Upgrading Microsoft Visual Basic 6.0to Microsoft Visual Basic  .NET
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET w/accompanying CD-ROM
ISBN: 073561587X
EAN: 2147483647
Year: 2001
Pages: 179

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