inset
Visual Basic 6 Meets Windows Forms
Oct. 16, 2006

A new add-on to Visual Studio (VS) 2005 helps developers take forms created with C# or Visual Basic .NET (VB.NET) and make them accessible from Visual Basic (VB) 6. In principle, the Interop Forms Toolkit could make it easier for developers to migrate VB 6 applications to .NET incrementally by replacing individual forms with newer versions based on the .NET Framework. However, the process is far from seamless: developers must write custom code in both the .NET form and the VB 6 application and debugging is complex.

Supporting Hybrid Applications

The goal of the Interop Forms Toolkit is to allow developers to move a VB 6 application to .NET incrementally by replacing individual forms (the term used in VB to describe an interface window) in the application with new versions written using the .NET Framework. The idea is that rather than rewriting an application from scratch, a developer could migrate it piece by piece. The newer pieces could take advantage of some of the .NET Framework features, such as improved layout for forms and support for Web services.

The toolkit builds on existing .NET Framework support for COM interoperability but is customized for some specific needs of VB forms.

To use the toolkit, a developer uses VS 2005 to create a form with either the C# or VB.NET programming languages. When the form is completed, the developer uses a VS add-in, provided by the toolkit, to generate a COM "wrapper" for the form. This wrapper can then be used with VB 6 to create and run the .NET form within a VB 6 application.

But a VB form is not a self-contained entity; it often interacts with other forms in the application as well as the application itself. The Interop Forms Toolkit includes several components to help that integration, including the following:

  • An Event Messenger that forwards events, such as when a form is displayed or closed, to the application
  • A component that allows the form and the containing application to share state information, such as the current user's name and other network credentials.

Not Plug and Play, No Change in Support

Although the toolkit could help developers create hybrid applications, the process is not automatic and has several limitations, including the following:

Custom code is required. Although the toolkit takes care of much of the plumbing, developers must write custom code in both the VB 6 application and the .NET form. For example, the code that a developer writes to fire an event to a VB 6 application differs from the code used to fire an event in pure .NET applications.

Forms interaction is quirky. For example, multiple document interface (MDI) applications are not supported and bringing one VB 6 form to the front makes all VB 6 forms come to the front.

Debugging is complex. Developers can't automatically step from VB 6 code to .NET code but must start both the VS and VB 6 development environments and use VS's Attach to Process feature to connect the VS debugger to VB 6. Furthermore, because VB 6 uses a single OS process to hold the integrated development environment, debugger, and the application being debugged, stopping at a breakpoint in the VS debugger stops the entire VB 6 development environment, making it very difficult to examine the VB 6 code while the application is stopped.

An additional deployment step is required. The .NET form, along with any other .NET components it uses, must be installed on the system.

Furthermore, the Interop Forms Toolkit doesn't mark any change in Microsoft's basic strategy: the company wants developers to migrate from VB 6 to VS and the .NET Framework. In fact, Microsoft didn't build the Interop Forms Toolkit itself but instead relied on Clarity Consulting, a company with a long history of working with the VB product team.

IT organizations with significant applications running on VB 6 must still decide how long they want to continue to use a tool that is no longer in Mainstream support and whether incremental migration is a better approach than rewriting.

The Interop Forms Toolkit can be downloaded from www.microsoft.com/downloads/details.aspx?FamilyID=98C38C1D-C630-4D9A-8BB5-7F1FC088A7C4.