Debugging Visual Basic 6.0 Code

Debugging Visual Basic 6.0 code in a Hybrid application is no different than debugging any other Visual Basic 6.0 project. Press F5 to run, set breakpoints, and debug as you normally would. There are two different methods for stepping into your .NET — by attaching to a process from Visual Studio .NET, or by setting a Start Action in Visual Studio.

Debugging with Attach to Process

You will not be able to step into .NET code, however, without performing a few additional steps. Follow these steps to debug your .NET code:
  1. Load your .NET project in Visual Studio.
  2. Build the .NET project if it has not already been built.
  3. Load your Visual Basic 6.0 code in the Visual Basic 6.0 IDE.
  4. Run your application by pressing F5 in the Visual Basic 6.0 IDE (Note: You must do this once before attaching the .NET debugger to properly load the .NET code).
  5. In Visual Studio, select Attach to Process... from the Debug menu.
  6. In the dialog that appears, select the VB6.exe process (Note: because the Visual Basic 6.0 code runs within the Visual Basic 6.0 IDE, you must select this process to debug).
You only need to repeat the steps above after rebuilding .NET code. The Visual Basic 6.0 IDE must be closed when rebuilding. After completing these steps, press F5 in the Visual Basic 6.0 IDE to run, set breakpoints, and debug as you normally would. Remember that since the Visual Basic 6.0 IDE process is being debugged, you will not be able to navigate in the Visual Basic 6.0 code while stopped on a breakpoint.

Debugging with Start external program

Instead of manually attaching to the process every time, you can configure your Visual Studio project to automatically launch Visual Basic 6.0. To debug in Visual Studio, you can set the debugger to start an external program, and pass it the path to the Visual Basic 6.0 application. When you run the project in Visual Studio, your Visual Basic 6.0 project will be launched; you can then set breakpoints in Visual Basic 6.0 and step into the .NET code.

Note: Both Interop UserControls and InteropForms cannot be built or debugged in Visual Studio .NET while an instance is open in Visual Basic 6.0.

Note: If any changes are made in Visual Basic 6.0 during debugging you must explicitly save your changes. When you stop debugging in Visual Studio .NET, Visual Basic 6.0 will be terminated without prompting to save changes.
  1. Close the Visual Basic 6.0 IDE.
  2. In Visual Studio, in Solution Explorer right-click the Properties node and click Open.
  3. In the project properties dialog, select the Debug tab, and under Start Action select Start external program.
  4. In the text box, type vb6.exe. Note that if vb6.exe is not defined as an environment variable you may have to browse to your Visual Basic 6.0 directory in order to include the path.
  5. In the Command line arguments field, type the full path to your Visual Basic 6.0 project, i.e. "C:\Projects\InteropProject.vbp". Note that the path and filename must be enclosed in quotes.
  6. In Visual Studio, set breakpoints as needed and then press F5. The project will run and Visual Basic 6.0 will be launched and your project loaded.
  7. In Visual Basic 6.0, set breakpoints as needed and then press F5. As the application executes and a breakpoint is hit, you can press F8 to step into the Visual Studio code. If you make changes in Visual Basic 6.0, you must save your changes before you stop debugging in Visual Studio or your changes will be lost.

Static Memory

When you run an application in the Visual Basic 6.0 IDE, it does not launch in a new process. This has the negative side effect of not clearing out shared variables (static memory) between runs.

Last edited Jan 16, 2012 at 6:38 AM by HolisticDeveloper, version 1

Comments

No comments yet.