Fix error handling for winapi functions.