Win32 build fixes

These commits fix a bunch of issues that are breaking the MSVC build.

The last fix (atomic) is not the most clean, but I do not see a clean of non-intrusively fixing this in C/MSVC while keeping the same interface. MSVC does not provide the typeof operator in C mode. Only way I can see is changing the build to use the C++ compiler and use typeof from there, but that would be a lot of work because of incompatible C code. Since the macro is just used for this case, I expanded the code manually.