Patches for Microsoft Visual Studio

This is a repackaging of Lukas Korous' patches in #273 . I've taken those parts of the patches that compile and put them into separate commits. This supersedes and closes #273 .