More patches for Windows compatibility

cherry-picked (and slightly adapted) commits from Andre Schulz's win32 branch