Module: wine Branch: master Commit: 2784c1caa0a84ada15a37a457dc7d9d5156d9f0e URL: https://gitlab.winehq.org/wine/wine/-/commit/2784c1caa0a84ada15a37a457dc7d9d...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Sep 13 22:23:55 2022 +0200
win32u: Fix Get/SetWindowWord behavior on 32-bit.
---
dlls/user.exe16/message.c | 2 +- dlls/user.exe16/window.c | 20 ++++++++++++++++++-- dlls/user32/tests/win.c | 20 -------------------- dlls/win32u/window.c | 33 +++++++-------------------------- 4 files changed, 26 insertions(+), 49 deletions(-)
diff --git a/dlls/user.exe16/message.c b/dlls/user.exe16/message.c index 46561d722ed..9af217bf5f1 100644 --- a/dlls/user.exe16/message.c +++ b/dlls/user.exe16/message.c @@ -248,7 +248,7 @@ static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPA
memset(&context, 0, sizeof(context)); context.SegDs = context.SegEs = CURRENT_SS; - if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs; + if (!(context.Eax = (WORD)GetWindowLongA( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs; context.SegCs = SELECTOROF(func); context.Eip = OFFSETOF(func); context.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME, bp); diff --git a/dlls/user.exe16/window.c b/dlls/user.exe16/window.c index e54dd6a803e..69d178e31b0 100644 --- a/dlls/user.exe16/window.c +++ b/dlls/user.exe16/window.c @@ -838,7 +838,15 @@ LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval ) */ WORD WINAPI GetWindowWord16( HWND16 hwnd, INT16 offset ) { - return GetWindowWord( WIN_Handle32(hwnd), offset ); + switch(offset) + { + case GWLP_ID: + case GWLP_HINSTANCE: + case GWLP_HWNDPARENT: + return GetWindowLongA( WIN_Handle32(hwnd), offset ); + default: + return GetWindowWord( WIN_Handle32(hwnd), offset ); + } }
@@ -847,7 +855,15 @@ WORD WINAPI GetWindowWord16( HWND16 hwnd, INT16 offset ) */ WORD WINAPI SetWindowWord16( HWND16 hwnd, INT16 offset, WORD newval ) { - return SetWindowWord( WIN_Handle32(hwnd), offset, newval ); + switch(offset) + { + case GWLP_ID: + case GWLP_HINSTANCE: + case GWLP_HWNDPARENT: + return SetWindowLongA( WIN_Handle32(hwnd), offset, newval ); + default: + return SetWindowWord( WIN_Handle32(hwnd), offset, newval ); + } }
diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 6daef2ffa44..5f2e11ce367 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -7090,33 +7090,25 @@ static void test_set_window_long_size(void) retval = GetWindowLongPtrA(hwnd, GWLP_USERDATA); ok(retval > 123, "Unexpected user data.\n"); ret = GetWindowWord(hwnd, GWLP_USERDATA); - todo_wine ok(ret == 123, "Unexpected user data %#lx.\n", ret); ret = SetWindowWord(hwnd, GWLP_USERDATA, 124); - todo_wine ok(ret == 123, "Unexpected user data %#lx.\n", ret); ret = GetWindowLongA(hwnd, GWLP_USERDATA); - todo_wine ok(ret == 124, "Unexpected user data %#lx.\n", ret); retval = GetWindowLongPtrA(hwnd, GWLP_USERDATA); - todo_wine ok(retval == 124, "Unexpected user data.\n");
SetWindowLongA(hwnd, GWLP_USERDATA, (1 << 16) | 123); ret = GetWindowLongA(hwnd, GWLP_USERDATA); ok(ret == ((1 << 16) | 123), "Unexpected user data %#lx.\n", ret); ret = GetWindowWord(hwnd, GWLP_USERDATA); - todo_wine ok(ret == 123, "Unexpected user data %#lx.\n", ret);
ret = SetWindowWord(hwnd, GWLP_USERDATA, 124); - todo_wine ok(ret == 123, "Unexpected user data %#lx.\n", ret); ret = GetWindowLongA(hwnd, GWLP_USERDATA); - todo_wine ok(ret == ((1 << 16) | 124), "Unexpected user data %#lx.\n", ret); ret = GetWindowWord(hwnd, GWLP_USERDATA); - todo_wine ok(ret == 124, "Unexpected user data %#lx.\n", ret);
/* GWLP_ID */ @@ -7138,7 +7130,6 @@ static void test_set_window_long_size(void) ok(retval > 123, "Unexpected id.\n"); SetLastError(0xdeadbeef); ret = GetWindowWord(hwnd, GWLP_ID); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_INDEX, "Unexpected id %#lx.\n", ret);
/* GWLP_HINSTANCE */ @@ -7155,7 +7146,6 @@ static void test_set_window_long_size(void)
SetLastError(0xdeadbeef); ret = GetWindowWord(hwnd, GWLP_HINSTANCE); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_INDEX, "Unexpected instance %#lx.\n", ret);
SetLastError(0xdeadbeef); @@ -7181,7 +7171,6 @@ static void test_set_window_long_size(void)
SetLastError(0xdeadbeef); ret = GetWindowWord(hwnd, GWLP_HWNDPARENT); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_INDEX, "Unexpected parent window %#lx.\n", ret);
DestroyWindow(hwnd); @@ -7221,16 +7210,12 @@ static void test_set_window_word_size(void) ret = GetWindowLongA(hwnd, GWLP_USERDATA); ok(ret > 123, "Unexpected user data %#lx.\n", ret); ret = GetWindowWord(hwnd, GWLP_USERDATA); - todo_wine ok(ret == 123, "Unexpected user data %#lx.\n", ret); ret = SetWindowWord(hwnd, GWLP_USERDATA, 124); - todo_wine ok(ret == 123, "Unexpected user data %#lx.\n", ret); ret = GetWindowWord(hwnd, GWLP_USERDATA); - todo_wine ok(ret == 124, "Unexpected user data %#lx.\n", ret); ret = GetWindowLongA(hwnd, GWLP_USERDATA); - todo_wine ok(ret == ((1 << 16) | 124), "Unexpected user data %#lx.\n", ret);
/* GWLP_ID */ @@ -7241,11 +7226,9 @@ static void test_set_window_word_size(void)
SetLastError(0xdeadbeef); ret = GetWindowWord(hwnd, GWLP_ID); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_INDEX, "Unexpected id %#lx.\n", ret); SetLastError(0xdeadbeef); ret = SetWindowWord(hwnd, GWLP_ID, 2); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_INDEX, "Unexpected id %#lx.\n", ret);
/* GWLP_HINSTANCE */ @@ -7254,12 +7237,10 @@ static void test_set_window_word_size(void)
SetLastError(0xdeadbeef); ret = GetWindowWord(hwnd, GWLP_HINSTANCE); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_INDEX, "Unexpected instance %#lx.\n", ret);
SetLastError(0xdeadbeef); ret = SetWindowWord(hwnd, GWLP_HINSTANCE, 0xdead); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_INDEX, "Unexpected instance %#lx.\n", ret);
/* GWLP_HWNDPARENT */ @@ -7268,7 +7249,6 @@ static void test_set_window_word_size(void)
SetLastError(0xdeadbeef); ret = GetWindowWord(hwnd, GWLP_HWNDPARENT); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_INDEX, "Unexpected parent window %#lx.\n", ret);
DestroyWindow(hwnd); diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index d53dfde2fbb..d7263875b17 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -1101,20 +1101,10 @@ ULONG_PTR get_window_long_ptr( HWND hwnd, INT offset, BOOL ansi ) /* see GetWindowWord */ static WORD get_window_word( HWND hwnd, INT offset ) { - switch(offset) + if (offset < 0 && offset != GWLP_USERDATA) { - case GWLP_ID: - case GWLP_HINSTANCE: - case GWLP_HWNDPARENT: - break; - default: - if (offset < 0) - { - WARN("Invalid offset %d\n", offset ); - RtlSetLastWin32Error( ERROR_INVALID_INDEX ); - return 0; - } - break; + RtlSetLastWin32Error( ERROR_INVALID_INDEX ); + return 0; } return get_window_long_size( hwnd, offset, sizeof(WORD), TRUE ); } @@ -1354,6 +1344,7 @@ LONG_PTR set_window_long( HWND hwnd, INT offset, UINT size, LONG_PTR newval, BOO req->is_unicode = (win->flags & WIN_ISUNICODE) != 0; break; case GWLP_USERDATA: + if (size == sizeof(WORD)) newval = MAKELONG( newval, win->userdata >> 16 ); req->flags = SET_WIN_USERDATA; req->user_data = newval; break; @@ -1426,20 +1417,10 @@ LONG_PTR set_window_long( HWND hwnd, INT offset, UINT size, LONG_PTR newval, BOO */ WORD WINAPI NtUserSetWindowWord( HWND hwnd, INT offset, WORD newval ) { - switch(offset) + if (offset < 0 && offset != GWLP_USERDATA) { - case GWLP_ID: - case GWLP_HINSTANCE: - case GWLP_HWNDPARENT: - break; - default: - if (offset < 0) - { - WARN("Invalid offset %d\n", offset ); - RtlSetLastWin32Error( ERROR_INVALID_INDEX ); - return 0; - } - break; + RtlSetLastWin32Error( ERROR_INVALID_INDEX ); + return 0; } return set_window_long( hwnd, offset, sizeof(WORD), newval, TRUE ); }