This is ATF's standard method for measuring the length of gun barrels - it has been documented to be the case for shotguns and rifles. I haven't found anything stating that this is the standard method for handguns, but technically it should be fine.
Procedure
Unload the weapon.
Close the action.
Cock the action (this is important - unless cocked, the firing pin will protrude from the bolt face and may not provide the correct measurement.
Run a dowel rod of approximately the bore diameter, down the barrel.
When the rod is down as far as it will go, mark the spot where the barrel and any permanently mounted attachments end on the rod. Screwed-on attachments do not count.
Measure the length of the rod between the mark you just made, and the end which you ran down the barrel.
In practice, unless you're pushing really close to a minimum length limit, you could just use a cleaning rod in place of a dowel. But if you're close, you should get a rod of the same diameter as the barrel. On shotguns especially, it's possible for a slightly-angled rod to measure a longer distance than a rod of the correct diameter.
-- SeanNewton - 24 Jan 2008