mingw-w64 compiles cleanly

If mingw-w64 compatibility is of interest, please merge. Fixes several build errors only, no runtime testing due to lack of device.