Let $G$ be a semisimple real Lie group and $M$ be a smooth manifold. The map on cohomology
$H^{\ast}(BG,\mathbb{C}) \rightarrow H^{\ast}(BT,\mathbb{C})\simeq \mathbb{C}[\mathfrak{h}]$
induced by the inclusion of a maximal torus $T \rightarrow G$ is an injection, with image $\mathbb{C}[\mathfrak{h}]^W$ the Weyl invariant functions on the Cartan. This algebra is the same as $\mathbb{C}[\mathfrak{g}]^G$, the adjoint invariant functions on the Lie algebra.
Now suppose I have a $G$-bundle $P$ on $M$, which is classified by a map $f: M \rightarrow BG$. How can I see that the map $\mathbb{C}[\mathfrak{g}]^G \simeq H^{\ast}(BG,\mathbb{C}) \rightarrow H^{\ast}(M,\mathbb{C})$ induced by pulling back along $f$ is the same as the Chern-Weil homomorphism?
In other words, if $\Omega$ is the curvature form of some connection on $P$, $A$ is an invariant polynomial on $\mathfrak{g}$, and $\alpha$ is the corresponding cohomology class on $BG$, why is $f^{\ast}\alpha$ cohomologous to $A(\Omega)$?
If possible, I would also like to understand what happens when $G$ is a reductive complex Lie group.