受欢迎的博客标签

Excel VBA代码封装成Dll(VB6.0): Debug VB6 ActiveX DLL used inside Acad VBA code step by step

Published

Table of content

 Debug VB6 ActiveX DLL used inside Acad VBA code step by step

Stepping through VB6 COM object wrapped by .NET Class

 

 Debug VB6 ActiveX DLL used inside Acad VBA code step by step

I have a VB6 ActiveX dll which is used by AutoCAD. I would like to set a breakpoint and step through/debug the code. 

 

Debugging VB DLL used inside Acad VBA code is a bit tricky, but still simple
enough to do. Do the following steps:

 

1. Create your ActiveX DLL project in VB6. Complete your classes.
2. Inthe DLL project's properties window, "Debugging"tab, choose "Start
program" and point it to [Acad installation path]\acad.exe
3. Compile the DLL file;
4. Start AutoCAD and load your VBA, make sure the VBA project has reference
to to the DLL.

Note, you probably have already above 4 steps done.

5. Make sure AutoCAD is closed.
6. In VB6 IDE, hit F5 to start debugging, which launches Acad
7. Load your VBA project into Acad
8. Now you can set break point either in Acad VBA code or in VB6 DLL code
9. Run macro/form in the VBA project, which calls code in DLL with break
point set.

Now, the break point will be hit as long as your code logic says so. Then
you can step line by line thereafter.

 

Debugging VB6 ActiveX DLL called by excel VBA

Step 1:Set vb6 ActiveX DLL    Start program 

Try to use VB | Project | <project name> - Properties | Debugging tab.
Select appropriate settings on this tab.

In the DLL project's properties window, "Debugging"tab, choose "Start
program" and point it to [C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE]

C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE

Step 2:In VB6, start the DLL.

Now run your DLL from within Visual Studio.

step 3:set a reference to vbp file

From Excel, remove all references to the DLL. Close the references dialog and save the workbook.

Now run your DLL from within Visual Studio. From Excel, VBAIDE, Tools, References, Browse, set a reference to the "currently running" vbp file. NOT the dll file. You cannot debug a dll file on the run in VB.

D:\developer\src\vbadll\VBADLL.vbp
Visual Basic Project (.vbp)

 

https://www.mrexcel.com/board/threads/debugging-a-vb6-dll-used-in-excel.325709/

 

Stepping through VB6 COM object wrapped by .NET Class

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!!

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.

https://stackoverflow.com/questions/6367332/stepping-through-vb6-com-object-wrapped-by-net-class