I have done this with Beretta 96 mag's in a Beretta 92 and it works with no problems, fired as reliable as my 92 magazines.
Tried 40 cal magazines in my Glock 17 and it did not work, feed lips are not tight enough to hold onto the 9mm rounds. I found they popped out very easily, feed lips would need to be squeezed closer to the approx width of a 9mm magazine. Problem with this is you are then altering the magazine. Altering the feed lips to hold onto the 9mm rounds will make the magazine illegal when using 9mm rounds and you can be charged with having a prohibited magazine. I only tried this with one 40cal magazine but it would not work for me.