Fix some compilation issues on Windows.

And do some minor ports.