Issue was caused by TlsGetValue always resetting error to ERROR_SUCCESS. This change fixes GetCursorPos resetting last-error randomly.
Signed-off-by: Rafał Harabień rafalh1992@o2.pl --- dlls/user32/tests/input.c | 11 ++++++++++- dlls/winex11.drv/x11drv.h | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c index 8f2576d..6ce03f8 100644 --- a/dlls/user32/tests/input.c +++ b/dlls/user32/tests/input.c @@ -1928,8 +1928,17 @@ static void test_Input_mouse(void) DWORD thread_id; POINT pt, pt_org; MSG msg; + BOOL ret;
- GetCursorPos(&pt_org); + SetLastError(0xdeadbeef); + ret = GetCursorPos(NULL); + ok(!ret, "GetCursorPos succeed\n"); + ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_NOACCESS, "error %lu\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = GetCursorPos(&pt_org); + ok(ret, "GetCursorPos failed\n"); + ok(GetLastError() == 0xdeadbeef, "error %lu\n", GetLastError());
button_win = CreateWindowA("button", "button", WS_VISIBLE | WS_POPUP, 100, 100, 100, 100, 0, NULL, NULL, NULL); diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index 721c082..6786a08 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -345,7 +345,12 @@ extern DWORD thread_data_tls_index DECLSPEC_HIDDEN;
static inline struct x11drv_thread_data *x11drv_thread_data(void) { - return TlsGetValue( thread_data_tls_index ); + /* TlsGetValue always resets last error */ + unsigned long err = GetLastError(); + struct x11drv_thread_data *data = TlsGetValue( thread_data_tls_index ); + if (err != ERROR_SUCCESS && GetLastError() == ERROR_SUCCESS) + SetLastError(err); + return data; }
/* retrieve the thread display, or NULL if not created yet */