Using Visual Basic 6 with Visual Basic .NET: COM Interop

Chapter 9

Using Visual Basic 6 with Visual Basic .NET: COM Interop

This chapter focuses on making your Visual Basic 6 and Visual Basic .NET applications work together. The mechanism that makes interoperability between the two products possible is known as COM interop. We ll start by looking at the various ways you can create or use existing components that communicate across COM and .NET component boundaries. We ll also show you how to debug across calls between Visual Basic 6 and Visual Basic .NET authored components. Finally, we ll discuss the role of binary compatibility in Visual Basic .NET.

If you ve been creating multitiered applications using Visual Basic 6, your application has likely evolved into a large system spanning multiple components. Let s say, for example, that you have an application composed of a Visual Basic standard EXE front end containing ActiveX controls talking to a middle-tier Visual Basic DLL. The Visual Basic DLL in turn talks to a back-end SQL Server database. Upgrading such an application to Visual Basic .NET in one shot is nearly impossible. This is where COM interop swoops in to save the day.

COM interop allows you to upgrade one component at a time while keeping the system alive. For example, you can upgrade your Visual Basic 6 middle-tier component to Visual Basic .NET independently of the user interface (UI) component. Once you have tested your new Visual Basic .NET component with your Visual Basic 6 UI client, you can update the client to take advantage of the new Visual Basic .NET server component. At a later date you may decide to upgrade your Visual Basic 6 client components to Visual Basic .NET components. An ActiveX control vendor may offer a .NET upgrade to your favorite ActiveX control, leading you to replace all ActiveX versions of the control in your application with the .NET version. Eventually your entire system evolves to .NET, smoothly and without interruption.

Visual Studio .NET Is Built on COM Interop

You do not need to look far for an example of COM interop at work. If you re running Visual Studio .NET, COM interop is right under your nose. The Property Browser is written in C#, a language built on the .NET Framework. Most of the designers you will find, such as the Windows Forms designer, are written in a language supported by .NET. All of the wizards are written in either C# or Visual Basic .NET. The Visual Studio .NET environment is a traditional client application written in C++ that interoperates with these other .NET components using COM interop. The Upgrade Wizard relies heavily on COM interop to accomplish its tasks. The wizard is a .NET component that calls out to the upgrade engine, an out-of-process COM EXE server, to upgrade your Visual Basic 6 project. The upgrade engine in turn calls back to the wizard to provide status. As your application is being upgraded, the status text and progress bar updates you see are brought to you by way of COM interop.

We look forward to the day when 100 percent of our Visual Studio .NET components are written in Visual Basic .NET. Until that day, COM interop will be silently at work keeping Visual Studio .NET humming along.

It would be nice to be able to upgrade your entire application to .NET, but in some cases it may not be feasible. For example, what if your application relies on a COM component for which there is no .NET equivalent? A good example is a Visual Basic 6 ActiveX document or DHTML page designer for which there is no equivalent component in .NET. In such cases COM interop can help keep things running without hindering you from moving other parts of your system forward to Visual Basic .NET.

Although we ve been talking about interoperation among Visual Basic components, the concept of interoperation applies to all COM components. For example, your application may be composed of a Visual Basic front end talking to a C++ authored middle-tier component. As long as the components that make up your application are based on COM, your Visual Basic .NET application can continue to talk to them. Similarly, your Visual Basic 6 application can continue to talk to a .NET component authored in any language supported by .NET as if it were a COM component, without any changes in your Visual Basic 6 application.



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