There is an important difference. With stocks, the punter wins on average. With gambling, the punter loses on average.
You can still lose all your money on stocks, with a combination of bad choices and bad luck. But it is much easier to lose it on the horses.
The punter does not win on average with stocks due to fees and spread.