Excellent point---
The rapidly expanding gases(created by burning powder) do the velocity work. The longer the barrel, up to a certain point, allow the gases to push on the bullet for a longer period of time, hence an increase in velocity with the same max pressure.