fixed cross compilation for windows

Tested with Minimalist GNU win32 4.2.1 and MinGW-w64 2.0.3-1.

Also fixes some compiler warnings