Dragons should be strictly used as light, hit and run aerial units
If you wanted to incorporate dragons into a medieval setting with cannons and muskets, they should be strictly used as shock units. Their main tactic should be to flank the enemy, use their breath to disrupt enemy formations and quickly retreat to avoid receiving any long range fire, then returning whenever there's an opportune moment. Basically, you're looking for hit and run tactics, dropping them into the front line or even assaulting the enemy head-on would have the enemy instantly focus their fire on them, most importantly their cannons to neutralize the obvious priority target.
Due to their sheer size, trying to provide armor for dragons via barding would be pointless. Their scales are sufficient enough to count as moderate armor and adding any additional armor would seriously affect their speed, making them a far easier target to hit. Muskets themselves shouldn't be harmful to dragons from anything other than closest of ranges, but cannons are a completely different story (because they don't give a crap about armor and tend to obliterate any creature they hit regardless of its size).
The only piece of equipment that could be added to dragons without hampering them too much would be a saddle for a single rider, preferably a sharpshooter who could pick of any particular individual threat.
Alternatively, dragons could be easily used as elite personnel transports for the sake of infiltration, to drop commandos and spies behind enemy lines during the night. Speaking of night time, dragons would be the most potent threat out there when visibility is seriously low (as in night time and foggy weather), picking off enemies one swipe or one breath at a time.
Basically, you should be applying your dragons in the most sneakiest of ways possible, the less exposed they are to the enemy the more damage they can do over time. Unless their wings are neutralized, they should NEVER be used as conventional land troops. Their wings are their greatest asset and, to quote How To Train Your Dragon: "A downed dragon is a dead dragon."
PS EDIT: As far as magic goes, dragons are considered resilient to most common forms of magic so, unless they are being targeted by the most potent of spellcasters, they should be fine.