Fix lots of MSVC build errors (but not all)

I should probably re-test this on GCC...