Add support for locale-switching on Windows.

This addresses an issue mentioned in relation to #1696.

I put the cast in the wrong place.