fix headers and missing functions for MSVC/MinGW

There are multiple issues of missing headers on Windows (MSVC and MinGW)

Here is the proposed solution (works on VS 2013 and Mingw 4.9.1), it is the main part of Windows compatibility issues fixing.

Will also add comments to commit parts.
I'd do a `.hpp` and a `.cpp`, and conditionally compile the `.cpp` based on autotools detecting Windows, but I'd have to look up what the macro for that is...