In this paper, for the first time a method is proposed to compute electromagnetic effects in hadronic processes using lattice simulations. The method can be applied, for example, to the leptonic and semileptonic decays of light or heavy pseudoscalar mesons. For these quantities the presence of infrared divergences in intermediate stages of the calculation makes the procedure much more complicated than is the case for the hadronic spectrum, for which calculations already exist. In order to compute the physical widths, diagrams with virtual photons must be combined with those corresponding to the emission of real photons. Only in this way do the infrared divergences cancel as first understood by Bloch and Nordsieck in 1937. We present a detailed analysis of the method for the leptonic decays of a pseudoscalar meson. The implementation of our method, although challenging, is within reach of the present lattice technology.