Thanatos is correct; you must use a specially-made barrel to safely fire 9mm ammo in a .40 caliber Glock. The problem is the vertical cutout in the breech area of the slide. The .40 cutout is wider, as the .40 cartridge case is wider than a 9mm. If a stock 9mm barrel were used, it would fit too loosely in the wider cut slide, and could cause lock-up problems or extraction difficulties (if the barrel had too much side-to-side movement at the rear, the extractor might slip off the cartridge's rim). Because the parts would not fit together correctly, it is quite possible that the barrel and/or slide would be damaged/battered or by recoil forces.
There is another method that uses all Glock parts, but it is much more involved and expensive. You would need to get a complete 9mm G19 slide and barrel assembly, and a 9mm ejector housing. Then you'd have to learn to change-out the .40 caliber ejector housing for a 9mm housing in the frame, including swapping the connector into the new housing, and finally, install the 9mm slide assembly.
That's probably why the conversion barrels are so popular.
"Placement is power" -- seen in an article by Stephen A. Camp
(RIP, Mr. Camp; you will be remembered, and missed)