Debugging Hybrid VB6/.NET Applications

Published 03 July 07 05:11 PM

To wrap up this series of posts on hybrid applications with the Interop Forms Toolkit, I'd like to talk about debugging. There's a couple ways we can go about debugging with VB6 and Visual Studio and depending on where you're spending most of your coding time, you may opt for one method or the other.

The first way we can debug is by attaching to the running VB6.EXE process from Visual Studio. This works well if you are working primarily in VB6 code. You'll need to already have the VB6 IDE open and the project running in order to attach properly. Start your VB6 project from the VB6 IDE then go back to Visual Studio and select Tools --> Attach to Process and select VB6.EXE. It's important that the VB6 application is running and not in design mode when you attach.

Now you'll be able to set breakpoints in both Visual Studio and VB6 and have them step through each other by hitting F8. (NOTE: The Visual Basic Development Settings profile gives you the VB6 keyboard mappings, including F8 for stepping through code. If you just want F8 and not the other VB mappings, go to Tools --> Options --> Environment --> Keyboard and select the Debug.StepInto command.)

The other way to debug across both environments is to use the Debug Start Action. This method works well if you are primarily working in Visual Studio like when you are first creating your .NET controls/forms. This is because when you need to recompile your .NET assembly you'll sometimes need to close VB6 in order to see the new changes. This is because VB6 hangs onto the DLL while you're developing. It may be easier for you to set up debugging this way because VB6 is automatically started when you start the Debug from Visual Studio. But watch out, the VB6 IDE is also closed as well when you stop debugging in Visual Studio and so any changes that you make to your VB6 application (like via Edit and Continue) you'll need to remember to explicitly save by stopping the application in VB6 and saving the project.

To set this up, go to My Project --> Debug tab then select "Start External Program" and find your VB6.EXE (i.e. C:\Program Files\Microsoft Visual Studio6\VB98\VB6.EXE). Next you'll need to specify your VB6 project file and wrap the argument in quotes (i.e. "C:\VB6App\MyVB6App.vbp"). Finally you'll want to set the working directory appropriately. For instance, if you connect to a database file or other resources in the current directory then make sure you set that appropriately too.


Now when you start the Debug in Visual Studio, the VB6 IDE will open your project and you can then start the Debug there and set the necessary breakpoints.

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Beth Massi - Sharing the goodness that is VB said on July 3, 2007 10:02 PM:

One of the features of the latest Interop Forms Toolkit is the ability to develop UserControls in addition

# Rajesh said on March 14, 2008 11:45 AM:

"For instance, if you connect to a database file or other resources in the current directory then make sure you set that appropriately too" ---- Can you give an example for the above sentence ?

# Paul Maher - Tales of a Microsoft Evangelist said on June 4, 2008 3:03 PM:

I have been working on several Visual Basic projects recently, so thought it would be useful to signpost

# UK ISV Blog said on June 12, 2008 4:55 AM:

Paul Maher, Microsoft UK Developer & Platform group, has pulled together some useful material for

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About Beth Massi

Beth is a Program Manager on the Visual Studio Community Team at Microsoft and is responsible for producing and managing content for business application developers, driving community features and team participation onto MSDN Developer Centers (http://msdn.com), and helping make Visual Studio one of the best developer tools in the world. She also produces regular content on her blog (http://blogs.msdn.com/bethmassi), Channel 9, and a variety of other developer sites and magazines. As a community champion and a long-time member of the Microsoft developer community she also helps with the San Francisco East Bay .NET user group and is a frequent speaker at various software development events. Before Microsoft, she was a Senior Architect at a health care software product company and a Microsoft Solutions Architect MVP. Over the last decade she has worked on distributed applications and frameworks, web and Windows-based applications using Microsoft development tools in a variety of businesses. She loves teaching, hiking, mountain biking, and driving really fast.

This Blog

Syndication

Page view tracker