Buying a share of a either a publicly traded company or a private one is investing in the company.  The seller is divesting.  It is not gambling, though many see it as such.

Companies can raise working capital by issuing new shares, which are priced based on the market value of traded shares, which is negatively impacted by taxes on investment gains.  This is all real world stuff.