A QCD relation between electromagnetic mass differences of charmed mesons and strange baryons