Windows code updates

This pull request contains a subset of the changes from #36. Specifically, I've checked that the changes don't affect the non-Windows code, or that they're safe. I've taken out the changes that would certainly have needed more testing.

The idea is that this moves the Windows code base along for others to hack on, but it's by no means complete or probably even functional.