Hm. I'm running on a x64 Win10 box as well and even with that modification crash or hang the terminal. Perhaps it has something to do with terminal settings...
In either case, I suppose to do this reliably I'd need to use the Windows API functions as mentioned.