Changed DOS extended error handling to be based on SetLastError; should be more thread-safe this way.