Added missing header and error handling.
Changed to use _WIN32 macro instead of WIN32.