Generating MAP files for VB6 programs

Here’s a handy tip I found on my travels for debugging a VB6 application which crashes with a general protection fault. It is possible to get the VB6 compiler to create a map file containing information about the executable in text form, which can then be very handy if you’re looking at the crash in a dump file. (Maybe I’ll look at how to generate dump files in a future post)

Visual Basic 6.0 compiles your executable using the same sequence of operations that a C++ compile would take. First, each module of the source code is compiled to an intermediate ‘object’ file, and then all of the object files are linked together to create an executable. In practice, VB6 actually uses the same linker program that the C++ toolset uses: LINK.EXE

So how does that help? While there’s no way that you can control the compile process from within the VB6 IDE, it is possible to control the operation of the linker using an environment variable. Just define a environment variable called ‘LINK’ with a value of ‘/MAP’. This will cause the linker to emit a .map file in the same directory as the executable when you rebuild the project. This is a text file containing address information of all of the procedures contained in the exe.

As the location of each procedure can change from build to build, it’s worthwhile creating and storing the map file for every build you release. That way you know you’ll have exactly the right information that matches the executable your user is running when it crashes sometime in the future.

This entry was posted in Visual Basic 6.0 and tagged , . Bookmark the permalink.

1 Response to Generating MAP files for VB6 programs

  1. VB6 Programming says:

    Useful VB6 programming tip

Leave a comment