Gleason has recently shown that the weight enumerators of binary and ternary self-dual codes are polynomials in two given polynomials. In this paper it is shown that classical invariant theory permits a straightforward and systematic proof of Gleason\´s theorems and their generalizations. The joint weight enumerator of two codes (analogous to the joint density function of two random variables) is defined and shown to satisfy a MacWilliams theorem. Invariant theory is then applied to generalize Gleason\´s theorem to the complete weight enumerator of self-dual codes over

, the Lee metric enumerator over

(given by Klein in 1884!) and over

(given by Maschke in 1893!), the Hamming enumerator over

, and over

with all weights divisible by 2, the joint enumerator of two self-dual codes over

, and a number of other results.