EDIT: I’ve finally gotten around to publishing the source for this addin on CodePlex.
https://bookmarksavevb6.codeplex.com
EDIT 7/25/2012: I’ve just updated the addin (see the ZIP download below) to correct a problem that can occur if you have several projects loaded in a group, and have files of the same name loaded in each project, AND you set bookmarks or breakpoints in those files. In that case, the breakpoints/bookmarks can end up being restored to the wrong file when you load the group of projects. This won’t cause any problems in your code, but your bookmarks and breakpoints won’t be restored properly, and you might receive messages saying that “a breakpoint can’t be set on that line”, or something similar. Just download the latest version, unzip it and copy the dll over your existing dll.
If first blogged about this addin back here.
Essentially, the idea is to solve a long standing pet-peeve of mine with the VB6 IDE; the fact that it doesn’t save your bookmark or breakpoint locations from one run to the next.
Ugh!
That functionality wouldn’t have taken more than about 30 minutes for someone to implement on the VB team, but, alas, no one did, and I’ve spent far more time than I should have manually restoring breakpoints ever since.
If, like me, you’ve worked in VB.net for any amount of time, and you now find yourself, from time to time, having to load up your trusty copy of VB6 to do some maintenance work, you, almost certainly also like me, sorely lament that missing functionality.
But no more!
After quite a bit of teeth-gnashing, along with some very helpful testing comments from Sam (Thank You!), I think it’s about time to correct that long-suffered oversight!
Download the Addin here:
The Zip file contains one DLL. Just extract it where-ever you want, and run REGSVR32 on it (just like any other COM dll).
NOTE: You will have to have the .net framework 4.0 installed, as this addin is compiled in .net against that version of the framework. Why, you may ask? Well, frankly, VS2010 is much nicer to code in than VB6, and I was actually quite curious whether a VB6 Addin that performed a real, useful, function could be written in VB.net and act, more or less, just like an addin that had been written in VB6. Personally, with this, I think the answer is a pretty deafening “Oh Yeah!”…
DISCLAIMER: As with anything else around these parts, your mileage may vary (the normal “It works on my machine”). I’ve tested it in conjunction with a few of the addins I use (CodeSmart and MZTools, as well as the Mouse Wheel fix, and resource editor) and have had only one minor issue. If CodeSmart is loaded as well as BookmarkSave, CodeSmart causes the VB6 IDE to crash when you unload it, but only if you ran your application in the VB6 IDE. If this scares you, don’t download or install this addin. I worked around a number of CodeSmart “peculiarities” concerning the way they happen to subclass VB IDE code windows, but so far, the source of this problem eludes me. The good news is that other than the Crash dialog, there doesn’t appear to be any other anomalies (your project saves fine, runs, etc). My suspicion is that during the Addin UNLOAD phase of the VB6 shutdown process, a pointer isn’t being released quite right.
Using the Addin
Well, it can’t get much simpler. Once you’ve registered it, load up VB6 and check the Addins Manager to make sure it’s loaded.
If it is, load up a project of your choice, set a few breakpoints and bookmarks, and close the project.
Reopen it in VB6 and you should see all your breakpoints and bookmarks wondrously reset just like they were before!
There aren’t really any settings or options to speak up.
Bookmarks are saved into an XML file called {projectname}.BM in the same folder as your project’s VBP file.
Breakpoints are saved into a {projectname}.BP file in the same place.
Naturally, you should probably not check those files into version control.
New Hotkeys
Sadly, VB6 doesn’t provide many convenient ways of navigating bookmarks and breakpoints, so this addin adds a few.
Ctrl-K – Toggle a bookmark at the current cursor location
Alt-Left or Right – Navigate to the next or previous bookmark
Alt-Up or Down – Navigate to the next or previous breakpoint
These aren’t configurable at this time.
A few interesting bits
None of this is necessary to actually use the Addin, but I’ll mention it for the curious:
First, I make use of my DLLExport utility to actually export the DLLRegisterServer and DLLUnregisterServer functions, so that the DLL can self register with COM, just like a VB6-authored DLL can. With all the other great COM support in .net, this is a really glaring omission. I wrote about that technique here.
Next, I use my “GenerateLineMap” utility to strip line number info from the PDB file and embed it into the DLL. This information is then used during error handling to annotate any stack trace with real source code line numbers, without actually including the PDB as a separate file. This is a technique I’ve worked on for quite some time, and talked about here, here, and here. Still need to get that article written up.