Fix Windows build.

- Adapt to API changes.
- Fix of string manipulation.
- Compile out a switch case with no case but just a default (MSVC doesn't
  like this).
Merge pull request #1859 from darktears/win-build-fix

Fix Windows build.