For Glock barrel conversion, you have work from larger caliber to smaller caliber. But not the other way around. The reason for that is the outer dimension of barrel is different therefore a G22 barrel won't fit in G17 slide, and G17 barrel will be too loose in G22's slide. To convert from 40cal to 9mm, you will need a "Conversion Barrel". Lone Wolf and Storm Lake sell them pretty cheap. Need 9mm mag.
EX: You can convert G22 with a conversion barrel and shoot 9mm. But you can't convert a G17 to shoot 40 or 357sig.
For 40 cal Glock, you can use stock .357sig barrel and the outer dimension are the same. So you can convert them both way. And they use the same mag.
EX: you can use a G22 barrel in G31. Or a G31 barrel in G22. The frame are exactly the same, so are ejector/extractor.
For G20 (10mm), you can get conversion barrel to shoot either --> 40s&w, .357sig, 9mm.
Need the correct caliber mag.
There was an individual on Glock Talk mention some time ago, that he convert a G21 to shoot 10mm by drop in a G20 barrel. Even though the barrel fit loosely in the slide. And he test fire hundreds of round without any malfunction. But I don't recommend that for safety reason.
If OP's question only about how to convert a G17 to other caliber, you not only need a slide (either stock or after market, lone wolf and others do make them), you also need to change the ejector on the frame.
And of course there is 22 conversion kit out there that can convert most Glock model to 22 by an after market slide.