Added some SetLastError()s to get correct error codes in Win32.
Merge pull request #391 from TsudaKageyu/setlasterror

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