Ought to be a simple question, but the answer depends on how much you want to consider details.
For a specific named gun, you could say that the New Land Musket AKA Brown Bess has got to be a major contender. It was used by the British Army from 1722 until replaced by the 1842 musket. But there were a few variations in that time: the last ones were 7" shorter than the first, for example, so the exact same gun was not made and used continuously for 120 years.
If you want to go the towards the general direction- just say, "flintlock muzzle loading musket", those were used by the British army from about 1680 ( early ones unnamed: there was not a great deal of standardization until the 18th c. ). So, you could certainly say that a soldier in the Glorious Revolution in 1688 would know how to load and fire a musket from the Napoleonic Wars in 1815...that's a good 162 years.
But then, if you want to be general, probably the muzzle-loading matchlock musket/ arquebus would be the longest used. Earliest date is uncertain, but probably by circa 1470 ( which is about 150 years after armies were first trying out the idea of a hand-held cannon) , and it was mostly obsolete only by 1700: so 230 years. And it continued to be used in some places, like Japan, for even longer than that.
Claude Blair : European and American Arms