Make CreateWindow with invalid menu handle test pass on Wine

Dmitry Timoshkov dmitry at baikal.ru
Tue Aug 9 01:58:01 CDT 2005


Hello,

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    Make CreateWindow with invalid menu handle test pass on Wine.

diff -up cvs/hq/wine/dlls/user/menu.c wine/dlls/user/menu.c
--- cvs/hq/wine/dlls/user/menu.c	2005-07-22 13:12:04.000000000 +0900
+++ wine/dlls/user/menu.c	2005-08-09 15:44:15.000000000 +0900
@@ -3790,6 +3790,7 @@ BOOL MENU_SetMenu( HWND hWnd, HMENU hMen
     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 -up cvs/hq/wine/dlls/user/tests/win.c wine/dlls/user/tests/win.c
--- cvs/hq/wine/dlls/user/tests/win.c	2005-08-09 12:55:33.000000000 +0900
+++ wine/dlls/user/tests/win.c	2005-08-09 15:43:30.000000000 +0900
@@ -2813,16 +2813,16 @@ static void test_params(void)
     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 -up cvs/hq/wine/dlls/user/win.c wine/dlls/user/win.c
--- cvs/hq/wine/dlls/user/win.c	2005-07-22 13:12:05.000000000 +0900
+++ wine/dlls/user/win.c	2005-08-09 15:48:38.000000000 +0900
@@ -1025,7 +1025,15 @@ static HWND WIN_CreateWindowEx( CREATEST
     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 );






More information about the wine-patches mailing list