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

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…

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 VisualBasic 6 application. Upgrading a Visual Basic 6 Client/Server Application. Suppose you have a Visual Basic 6 ActiveX DLL that acts as a language translator, translating a phrase in one language to another language. Your component is currently limited to rudimentary Spanish. The companion CD includes two Visual Basic 6 sample applications: TranslatorServer and TranslatorClient. In the following section we will demonstrate how to call the TranslatorServer component from a Visual Basic .NET client application. First, however, you need to build the Visual Basic 6 server component by following these steps: 1. Run Visual Basic 6. 2. Open TranslatorServer.Vbp provided on the companion CD. 3. Open TranslatorServer.Cls, and you will find that it contains the following code:….

Source: http://download.microsoft.com/

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

Leave a Reply