Added some SetLastError()s to get correct error codes in Win32.