Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid GetLastError result raised from others. #22

Closed
wants to merge 1 commit into from
Closed

Avoid GetLastError result raised from others. #22

wants to merge 1 commit into from

Conversation

fx-kirin
Copy link

It could raise the error from other methods. To specify the error from the method, I recommend to reset the LastError on Windows.
In addition, PIL.Image.Image.save() makes Windows Error 183 but automatically overwrite the file when the file has already existed. The error from this method isn't deleted after executed.

It could raise the error from other methods. To specify the error from the method, I recommend to reset the LastError on Windows.
In addition, PIL.Image.Image.save() makes Windows Error 183 but automatically overwrite the file when the file has already existed.  The error from this method isn't deleted after executed.
@asweigart
Copy link
Owner

From https://msdn.microsoft.com/en-us/library/windows/desktop/ms680627%28v=vs.85%29.aspx :

Most functions call SetLastError or SetLastErrorEx only when they fail. However, some system functions call SetLastError or SetLastErrorEx under conditions of success; those cases are noted in each function's documentation.

From checking out the docs for mouse_event, it seems that it doesn't set the "last error", so really this code shouldn't be calling GetLastError() at all. Since mouse_event is deprecated, this code should be calling SendInput(), which does modify the last error. This would make this commit's addition of SetLastError() unneeded.

What we should probably do is call SendInput() to correct the original problem. Thanks for pointing this out! I'll open an issue for it.

SendInput doc:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants