Support windows

I wrote these patches to support MS Windows.
After these patch, we can pass all tests by `rake test`.