Avoid GetLastError result raised from others. #22

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@fx-kirin

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.

Avoid GetLastError result raised from others.
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

This comment has been minimized.

Show comment
Hide comment
@asweigart

asweigart Feb 25, 2015

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

Owner

asweigart commented Feb 25, 2015

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