O'Reilly logo

Visual Basic 2005 Jumpstart by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using COM Objects in VB 2005

One of the primary reasons VB 6 programmers and their companies are reluctant to migrate to VB 2005 is the huge investments they have made in developing COM components. However, COM components continue to be supported in .NET. In the following sections, you will see how you can use legacy COM components in your VB 2005 applications.

The most direct way to use COM objects in VB 2005 is to use COM Interop. Although applications that run under the .NET Framework can only work with .NET components, .NET allows you to use your existing COM components by means of a Runtime Callable Wrapper (RCW). When you use RCW to interact with a COM object, an assembly is used as a wrapper for the COM object. The RCW acts as a bridge between the unmanaged code (the COM object) and managed code (your .NET application), and all communications with the COM object are routed through this class (see Figure 6-2).

Runtime Callable Wrapper

Figure 6-2. Runtime Callable Wrapper

Tip

COM objects are unmanaged code, therefore you need to remember to free up their resources when they are no longer in use.

To illustrate the support of COM in .NET, let's consider a simple example.

Suppose you want to display a PDF file in a VB 2005 Windows application. To do so, you can make use of the Adobe Acrobat Browser Document control (which is a COM object) installed on your system (the component is installed on your computer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required