A chest or a door differ from an enemy in as much as they cannot dodge your attacks. In other words, they do not have a defence rating.
To summarise how the chance to hit for ranged weapons is calculated:
Your dexterity influences your offence rating. An enemy has a defence rating (which is indirectly connected to the enemy's level). The ideal (!) chance to hit is calculated based on these two values.
Do not ask me the exact formula, but I think this would be something very simple like "Offence rating - defence rating".
This is your ideal chance to hit when your ranger is very close to the enemy. When your ranger moves away from the enemy, then the chance to hit starts to decrease - the rate of this decrease is 1% every 0.2 m. In order to counteract this reduction you have to improve your accuracy - which is influenced by the perception attribute.