5

I have a VB6 object that is wrapped by a .NET class. As far as I recall it is possible to step through a VB6 object by simply running the VB6 library and inserting a breakpoint at the desired location.

However this does not appear to be working in my case. I have attempted to recompile the VB6 object and re-reference it in my .NET project but this doesn't appear to have helped.

Where do I go from here? Is there a way to insert Debugger.Launch() equivalent into a VB6 project? Any help would be appreciated!!

1 Answer 1

9

Lifted from robgruen's blog:

If you are using interop to call into a VB6 ActiveX dll or exe and you need to debug your VB6 project you may find yourself having both VS.NET and the VB6 IDE open. This can certainly be far from efficient.

Typically you set your VB6 project to “Wait for the Component to be created” and you launch your .NET app and then hit breakpoints within the VB6 component. Well, there’s an easier way to do this. You can actually debug your VB6 component within VS.NET. Here’s what you need to do:

1) Build your VB6 project with symbols.In VB6 open up your vbp file and goto “Project->Properties.” Select the “compile” tab and check “Compile to Native Code.” Then select the “No Optimization” radio button and check “Create Symbolic Debug Info.”

This will generate a .PDB (Program Database) file along with your .EXE. This file contains the debugging information so the VS.NET debugger can line up source and hit breakpoints, etc. (Make sure you have binary compatibility on your VB6 dll set or you’ll have to drop and re-add your reference to the VB6 component in VS.NET.)

2) Open your .NET project in VS.NET.

3) Go to the project properties and select the “Configuration Properties->Debugging” property page and enable unmanaged debugging.
For VB.NET projects this option is “Unmanaged code debugging” and for C# is “enable unmanaged debugging.”

4) Select the property page for the solution.

5) Add to the “Debug Source Files” an entry that points to the path where the source code is for the VB6 component.

6) Add to the “Debug Symbols Files” an entry that points to the folder where the .PDB file is that was generated in step 1.

7) You should now be able to open your .bas, .cls, .frm, etc. files in VS.NET and you can put breakpoints in the file. Once you debug the debugger will stop on those lines of code.

Sign up to request clarification or add additional context in comments.

4 Comments

Note as an additional step for Visual Studio 2013 and newer in VS you need to go to Debug->Options and Settings then check the box for Use Managed Compatibility Mode. VS2013 uses a new debugger engine and the method described in this post does not work with it, however checking that box makes it use the old debugger mode and the ability to step through vb6 code works again.
@ScottChamberlain, Im using VS13 also. Did you have to follow steps 4- 7
@crh225 Kinda, I don't do 5, in 6 I have it the symbol file location loaded in my Configuration Properties->Debugging->Symbols settings. For 7, I can never get "step in-to" to work from going from C# to vb6 but if I open the vb6 file and put a breakpoint in it it does hit the breakpoint and stop.
@ScottChamberlain I think these would be one of those times, a video would help. I followed the steps with no luck. I have a .net exe referencing a vb6 dll.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.