Make CreateWindow with invalid menu handle test pass on Wine.
diff --git a/dlls/user/menu.c b/dlls/user/menu.c index 2a8b51c..24fd853 100644 --- a/dlls/user/menu.c +++ b/dlls/user/menu.c
@@ -3790,6 +3790,7 @@ if (hMenu && !IsMenu(hMenu)) { WARN("hMenu %p is not a menu handle\n", hMenu); + SetLastError(ERROR_INVALID_MENU_HANDLE); return FALSE; } if (!WIN_ALLOWED_MENU(GetWindowLongW( hWnd, GWL_STYLE )))
diff --git a/dlls/user/tests/win.c b/dlls/user/tests/win.c index f6a6641..41cc1cf 100644 --- a/dlls/user/tests/win.c +++ b/dlls/user/tests/win.c
@@ -2813,16 +2813,16 @@ rc = GetWindowText(hwndMain2, NULL, 1024); ok( rc==0, "GetWindowText: rc=%d err=%ld\n",rc,GetLastError()); + SetLastError(0xdeadbeef); hwnd=CreateWindow("LISTBOX", "TestList", (LBS_STANDARD & ~LBS_SORT), 0, 0, 100, 100, NULL, (HMENU)1, NULL, 0); - todo_wine { - ok(hwnd==NULL, "CreateWindow(parent=NULL, ctlid!=0) should have failed\n"); - } - /* NT sets LastError to ERROR_INVALID_MENU_HANDLE - * but Win9x leaves it unchanged. So no test. - */ + + ok(!hwnd, "CreateWindow with invalid menu handle should fail\n"); + ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */ + GetLastError() == 0xdeadbeef, /* Win9x */ + "wrong last error value %ld\n", GetLastError()); } static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
diff --git a/dlls/user/win.c b/dlls/user/win.c index c2284ef..070c617 100644 --- a/dlls/user/win.c +++ b/dlls/user/win.c
@@ -1025,7 +1025,15 @@ if (((wndPtr->dwStyle & (WS_CAPTION|WS_CHILD)) == WS_CAPTION) || (wndPtr->dwExStyle & WS_EX_APPWINDOW)) { - if (cs->hMenu) MENU_SetMenu(hwnd, cs->hMenu); + if (cs->hMenu) + { + if (!MENU_SetMenu(hwnd, cs->hMenu)) + { + WIN_ReleasePtr( wndPtr ); + free_window_handle( hwnd ); + return 0; + } + } else { LPCSTR menuName = (LPCSTR)GetClassLongPtrA( hwnd, GCLP_MENUNAME );