http://bugs.winehq.org/show_bug.cgi?id=14855
Summary: Incorrect FindWindow/GetLastError error result when window not found Product: Wine Version: 1.1.2 Platform: PC OS/Version: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: -unknown AssignedTo: wine-bugs@winehq.org ReportedBy: vesselinpeev@hotmail.com
The following program (compiled to a Win32 binary) prints "Window not found (expected result)" under Microsoft Windows (tested with Vista), whereas it prints "Unexpected error, GetLastError() return value: 1407" when ran under Wine (tested with Wine 1.1.2).
It seems that FindWindow does not set the correct error value (ERROR_FILE_NOT_FOUND) when it doesn't find a window.
#include <windows.h> #include <stdio.h>
int main() { HWND hWnd = FindWindow("SomeWindowThatDoesNotExist", NULL); if(hWnd) { printf("hWnd not NULL"); } else { DWORD dwResult = GetLastError(); if(dwResult == ERROR_FILE_NOT_FOUND) { printf("Window not found (expected result)\n"); } else { printf("Unexpected error, GetLastError() return value: %lu\n", dwResult); } } return 0; }
http://bugs.winehq.org/show_bug.cgi?id=14855
Dmitry Timoshkov dmitry@codeweavers.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |testcase
--- Comment #1 from Dmitry Timoshkov dmitry@codeweavers.com 2008-08-13 11:22:01 --- Please add a test case for this behaviour to dlls/user32/tests/win.c, test_hwnd_message(), after the comment /* test FindWindow behavior */. Don't forget to add SetLastError(0xdeadbeef) call right before the FindWindow() call to make sure it's really FindWindow() who sets the last error.
http://bugs.winehq.org/show_bug.cgi?id=14855
--- Comment #2 from Austin English austinenglish@gmail.com 2008-08-13 17:02:17 --- Created an attachment (id=15403) --> (http://bugs.winehq.org/attachment.cgi?id=15403) test in git format
Here's the test in git format. I'll submit it shortly.
http://bugs.winehq.org/show_bug.cgi?id=14855
--- Comment #3 from Austin English austinenglish@gmail.com 2008-08-13 17:04:16 --- http://www.winehq.org/pipermail/wine-patches/2008-August/059427.html
Sent
http://bugs.winehq.org/show_bug.cgi?id=14855
--- Comment #4 from Louis Lenders xerox_xerox2000@yahoo.co.uk 2008-08-20 15:45:40 --- Created an attachment (id=15508) --> (http://bugs.winehq.org/attachment.cgi?id=15508) patch
here's a patch that fixes bug. i'll send it to wine-patches
http://bugs.winehq.org/show_bug.cgi?id=14855
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch
http://bugs.winehq.org/show_bug.cgi?id=14855
Nikolay Sivov bunglehead@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |bunglehead@gmail.com Component|-unknown |user32
http://bugs.winehq.org/show_bug.cgi?id=14855
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |download Status|UNCONFIRMED |NEW Ever Confirmed|0 |1
--- Comment #5 from Austin English austinenglish@gmail.com 2010-05-26 15:55:55 --- Still present.
http://bugs.winehq.org/show_bug.cgi?id=14855
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #15403|0 |1 is obsolete| |
--- Comment #6 from Austin English austinenglish@gmail.com 2010-05-26 15:56:16 --- Created an attachment (id=28300) --> (http://bugs.winehq.org/attachment.cgi?id=28300) testcase, compiled with mingw
http://bugs.winehq.org/show_bug.cgi?id=14855
Nikolay Sivov bunglehead@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC|bunglehead@gmail.com |
http://bugs.winehq.org/show_bug.cgi?id=14855
butraxz@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |butraxz@gmail.com
--- Comment #7 from butraxz@gmail.com 2012-05-18 05:43:43 CDT --- This bug has not been updated for two years and OP by four. Is this still an issue i current (1.5.4) or newer wine ? You may also close this as abandoned if you feel that that this is issue is no longer relevant to you.
http://bugs.winehq.org/show_bug.cgi?id=14855
Bruno Jesus 00cpxxx@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |00cpxxx@gmail.com
--- Comment #8 from Bruno Jesus 00cpxxx@gmail.com 2012-05-18 10:15:44 CDT --- Still present in wine 1.5.4.
https://bugs.winehq.org/show_bug.cgi?id=14855
--- Comment #9 from Ken Sharp imwellcushtymelike@gmail.com --- Is this still an issue in Wine 1.7.45 or later?
https://bugs.winehq.org/show_bug.cgi?id=14855
super_man@post.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |super_man@post.com
--- Comment #10 from super_man@post.com --- wine a.exe Unexpected error, GetLastError() return value: 1407
still valid 1.7.53
https://bugs.winehq.org/show_bug.cgi?id=14855
--- Comment #11 from super_man@post.com --- Patch partly applies.
patching file dlls/user32/tests/win.c Hunk #1 FAILED at 4789. 1 out of 1 hunk FAILED -- saving rejects to file dlls/user32/tests/win.c.rej patching file dlls/user32/win.c Hunk #1 succeeded at 1958 (offset 345 lines). Hunk #2 succeeded at 1970 (offset 345 lines).
wine 1.9.4-git
https://bugs.winehq.org/show_bug.cgi?id=14855
super_man@post.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |xerox_xerox2000@yahoo.co.uk
https://bugs.winehq.org/show_bug.cgi?id=14855
winetest@luukku.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |winetest@luukku.com
https://bugs.winehq.org/show_bug.cgi?id=14855
Nikolay Sivov bunglehead@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Assignee|wine-bugs@winehq.org |bunglehead@gmail.com
https://bugs.winehq.org/show_bug.cgi?id=14855
Nikolay Sivov bunglehead@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Assignee|bunglehead@gmail.com |wine-bugs@winehq.org
https://bugs.winehq.org/show_bug.cgi?id=14855
Nikolay Sivov bunglehead@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement Status|NEW |NEEDINFO
--- Comment #12 from Nikolay Sivov bunglehead@gmail.com --- This behavior seems to apply to WinXP/2k3/Vista. Newer versions don't set this error. I'm not sure it's a good idea to make it match WinXP.
https://bugs.winehq.org/show_bug.cgi?id=14855
joaopa jeremielapuree@yahoo.fr changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |jeremielapuree@yahoo.fr
--- Comment #13 from joaopa jeremielapuree@yahoo.fr --- Bug still occurs with wine-5.4.
https://bugs.winehq.org/show_bug.cgi?id=14855
--- Comment #14 from winetest@luukku.com --- Unexpected error, GetLastError() return value: 1407
wine 5.21
https://bugs.winehq.org/show_bug.cgi?id=14855
Anastasius Focht focht@gmx.net changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEEDINFO |NEW CC| |focht@gmx.net
--- Comment #15 from Anastasius Focht focht@gmx.net --- Hello folks,
quoting from the discussion in https://stackoverflow.com/questions/63512609/findwindow-fails-but-getlasterr...
--- 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/2ad09b01673381261815bfc804a2f69c...
https://source.winehq.org/git/wine.git/blob/2ad09b01673381261815bfc804a2f69c...
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/2ad09b01673381261815bfc804a2f69c...
Regards