In the usual proof of the class number formula, i.e. the computation of the residue of the
Dedekind zeta function at $s = 1$, it is used that the class number is finite and that the unit group has the right number of generators. But the proof essentially works also if you do not use this fact, and in the end you get both results for free - the price you have to pay is a presentation which is a bit messier than usual because you have to allow for the possibility that h is infinite and that you have too few units. It is a good exercise to go through the proof in the real quadratic case, though.

**Edit.** The situation is not as simple as I thought it is. The problem is the following: by counting lattice points you can easily prove that the number of ideals with norm $< X$ in any given ideal class $C$ is equal to $cX + O(\sqrt{x})$. I would have thought that the existence of infinitely many ideal classes quickly produces nonsense, but this is wrong. In fact, the constants in the O-term may depend on the ideal classes. The usual proof of the finiteness of the ideal class group shows that there is a finite constant $c'$ such that the error term is less than $c' \sqrt{X}$. The problem is what to do without this information.

It follows, if I am right, quite easily that if $h$ is not finite, then the number of ideals with norm $< X$ is not of the form $O(x)$, i.e. grows fast than $cX$ for any constant $c$. In the quadratic case, using the fact that the number of ideals with norm $m$ can be expressed in terms of Legendre symbols implies that the number of ideals with norm $< X$ is $L(1,\chi) X + O(\sqrt{X})$, and now we get a contradiction plus a proof that $L(1, \chi)$ does not vanish (which in turn implies the fact that the Dedekind zeta function of the quadratic field has a pole of order $1$ in $s = 1$, if you know that it is analytic).

I have not yet seen what to do for general number fields.

hadto have some other argument for his exposition in the 1870s! Proof by example: see the proof of finiteness of the class number in Ireland and Rosen's book. They say their argument is due to Hurwitz, but that's wrong. It goes back earlier to Kronecker. See the comments to my answer of the question mathoverflow.net/questions/19021/… $\endgroup$ – KConrad Nov 6 '10 at 17:26