Chapter 7. Legacy COM Controls

Most Visual Basic 6 programmers have developed a library of COM controls, and are rightly concerned that when they move to .NET all this work will be lost.

Microsoft has made a commitment to ensure that these legacy components are usable from within .NET applications, and (perhaps less importantly) that .NET components are easily callable from COM.

In this chapter, you will add a relatively simple COM control to the NorthWindWindows application.

Importing ActiveX Controls

ActiveX controls are COM components that you can drop into a form. They may or may not have a user interface. When Microsoft developed the OCX standard, which allowed developers to build ActiveX controls in Visual Basic and use them with C++ (and vice versa), the ActiveX control revolution began. Over the past decade, thousands of such controls have been developed, sold, and used. They are small, easy to work with, and an effective example of binary reuse.

Importing ActiveX controls into .NET is surprisingly easy, considering how different COM objects are from .NET objects. Visual Studio 2005 is able to import ActiveX controls automatically.

Tip

As an alternative to using Visual Studio, Microsoft has developed a command-line utility, AxImp, that will create the assemblies necessary for the control to be used in a .NET application.

Creating an ActiveX Control

To demonstrate the ability to use classic ActiveX controls in a .NET application, you'll first develop a simple four-function calculator ...

Get Programming Visual Basic 2005 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.