Support building on win32

I only tested these changes on win32 so linux might need to be checked again.