[PATCH v2] Misc changes to get it work on MinGW