Add win32 support (merge from mdeters/win32, with some cleanup).