[Bug 14855] Incorrect FindWindow/GetLastError error result when window not found

WineHQ Bugzilla wine-bugs at winehq.org
Mon Nov 30 17:50:47 CST 2020


https://bugs.winehq.org/show_bug.cgi?id=14855

Anastasius Focht <focht at gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW
                 CC|                            |focht at gmx.net

--- Comment #15 from Anastasius Focht <focht at gmx.net> ---
Hello folks,

quoting from the discussion in
https://stackoverflow.com/questions/63512609/findwindow-fails-but-getlasterror-returns-0 

--- quote ---
The consensus from the comments seems to be that FindWindow simply doesn't set
an error if no window is found (Though other errors do, which I tested).
Personally, this seems like pretty misleading documentation, especially as
other function in the windows api will set an error code if they fail to do
their job, even if no actual errors occur, but I digress.
--- quote ---

--- quote ---
GetLastError does give more information. If it returns ERROR_SUCCESS, it means,
that you didn't find a window given your predicate, and this is not the result
of an error internal to the API trying to find an answer. 
--- quote ---

Even better:

--- quote ---
Like I said, it doesn't set an error at all, allowing previous errors to
propagate through. I agree now that in the example I gave, the given error did
give more info, but it doesn't always, which I think the documentation should
specify. 
--- quote ---

--- quote ---
Are you saying that if you call SetLastError(42); prior to calling FindWindow
(for a predicate that doesn't find a window), the return value is NULL and
GetLastError still returns 42? If that is the case, then you should not just
propose a documentation change, but also file a defect report. I don't know how
to file an API defect report in this day and age, though.
--- quote ---

--- quote ---
@IInspectable Yes, I tested to make sure, any previous errors will propagate
though. However I read the docs for GetLastError, which states; "Most
functions... ...set it when they fail... ...If the function is not documented
to set the last-error code, the value returned by this function is simply the
most recent last-error code to have been set". So it seems like this is simply
how the windows api works.
--- quote ---

The whole thread didn't mention the actual Windows version where this behaviour
was observed. Maybe Windows 10 but at least Windows 7.

I would suggest you focus on Windows 7+ behaviour and don't touch lasterror at
all in case the window wasn't found.

Extend the tests for lasterror behaviour:

https://source.winehq.org/git/wine.git/blob/2ad09b01673381261815bfc804a2f69ce4d85f86:/dlls/user32/tests/win.c#l8964

https://source.winehq.org/git/wine.git/blob/2ad09b01673381261815bfc804a2f69ce4d85f86:/dlls/user32/tests/win.c#l9020

Fix the lasterror behaviour of FindWindowA() by not setting
'ERROR_CANNOT_FIND_WND_CLASS' which would be consistent with FindWindowW() and
-Ex().

https://source.winehq.org/git/wine.git/blob/2ad09b01673381261815bfc804a2f69ce4d85f86:/dlls/user32/win.c#l2012

Regards

-- 
Do not reply to this email, post in Bugzilla using the
above URL to reply.
You are receiving this mail because:
You are watching all bug changes.



More information about the wine-bugs mailing list