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.
Just .h or .h + .cpp ?