Alexandre Julliard : user32: Avoid accessing the window structure directly in Get/SetWindowLong16.

Alexandre Julliard julliard at winehq.org
Wed Dec 23 10:04:10 CST 2009


Module: wine
Branch: master
Commit: 388814dfa975f8c57b199ed6870f58489be58acc
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=388814dfa975f8c57b199ed6870f58489be58acc

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Dec 22 15:25:15 2009 +0100

user32: Avoid accessing the window structure directly in Get/SetWindowLong16.

---

 dlls/user32/wnd16.c |   69 +++++++++++++++++---------------------------------
 1 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/dlls/user32/wnd16.c b/dlls/user32/wnd16.c
index dfcd71f..b4741ff 100644
--- a/dlls/user32/wnd16.c
+++ b/dlls/user32/wnd16.c
@@ -821,44 +821,36 @@ WORD WINAPI SetWindowWord16( HWND16 hwnd, INT16 offset, WORD newval )
 /**********************************************************************
  *		GetWindowLong (USER.135)
  */
-LONG WINAPI GetWindowLong16( HWND16 hwnd, INT16 offset )
+LONG WINAPI GetWindowLong16( HWND16 hwnd16, INT16 offset )
 {
-    WND *wndPtr;
+    HWND hwnd = WIN_Handle32( hwnd16 );
     LONG_PTR retvalue;
     BOOL is_winproc = (offset == GWLP_WNDPROC);
 
     if (offset >= 0)
     {
-        if (!(wndPtr = WIN_GetPtr( WIN_Handle32(hwnd) )))
-        {
-            SetLastError( ERROR_INVALID_WINDOW_HANDLE );
-            return 0;
-        }
-        if (wndPtr != WND_OTHER_PROCESS && wndPtr != WND_DESKTOP)
+        int cbWndExtra = GetClassLongA( hwnd, GCL_CBWNDEXTRA );
+
+        if (offset > (int)(cbWndExtra - sizeof(LONG)))
         {
-            if (offset > (int)(wndPtr->cbWndExtra - sizeof(LONG)))
+            /*
+             * Some programs try to access last element from 16 bit
+             * code using illegal offset value. Hopefully this is
+             * what those programs really expect.
+             */
+            if (cbWndExtra >= 4 && offset == cbWndExtra - sizeof(WORD))
             {
-                /*
-                 * Some programs try to access last element from 16 bit
-                 * code using illegal offset value. Hopefully this is
-                 * what those programs really expect.
-                 */
-                if (wndPtr->cbWndExtra >= 4 && offset == wndPtr->cbWndExtra - sizeof(WORD))
-                {
-                    offset = wndPtr->cbWndExtra - sizeof(LONG);
-                }
-                else
-                {
-                    WIN_ReleasePtr( wndPtr );
-                    SetLastError( ERROR_INVALID_INDEX );
-                    return 0;
-                }
+                offset = cbWndExtra - sizeof(LONG);
+            }
+            else
+            {
+                SetLastError( ERROR_INVALID_INDEX );
+                return 0;
             }
-            is_winproc = ((offset == DWLP_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG));
-            WIN_ReleasePtr( wndPtr );
         }
+        else if (offset == DWLP_DLGPROC) is_winproc = (DIALOG_get_info( hwnd, FALSE ) != NULL);
     }
-    retvalue = GetWindowLongA( WIN_Handle32(hwnd), offset );
+    retvalue = GetWindowLongA( hwnd, offset );
     if (is_winproc) retvalue = (LONG_PTR)WINPROC_GetProc16( (WNDPROC)retvalue, FALSE );
     return retvalue;
 }
@@ -867,33 +859,20 @@ LONG WINAPI GetWindowLong16( HWND16 hwnd, INT16 offset )
 /**********************************************************************
  *		SetWindowLong (USER.136)
  */
-LONG WINAPI SetWindowLong16( HWND16 hwnd, INT16 offset, LONG newval )
+LONG WINAPI SetWindowLong16( HWND16 hwnd16, INT16 offset, LONG newval )
 {
-    WND *wndPtr;
+    HWND hwnd = WIN_Handle32( hwnd16 );
     BOOL is_winproc = (offset == GWLP_WNDPROC);
 
-    if (offset == DWLP_DLGPROC)
-    {
-        if (!(wndPtr = WIN_GetPtr( WIN_Handle32(hwnd) )))
-        {
-            SetLastError( ERROR_INVALID_WINDOW_HANDLE );
-            return 0;
-        }
-        if (wndPtr != WND_OTHER_PROCESS && wndPtr != WND_DESKTOP)
-        {
-            is_winproc = ((wndPtr->cbWndExtra - sizeof(LONG_PTR) >= DWLP_DLGPROC) &&
-                          (wndPtr->flags & WIN_ISDIALOG));
-            WIN_ReleasePtr( wndPtr );
-        }
-    }
+    if (offset == DWLP_DLGPROC) is_winproc = (DIALOG_get_info( hwnd, FALSE ) != NULL);
 
     if (is_winproc)
     {
         WNDPROC new_proc = WINPROC_AllocProc16( (WNDPROC16)newval );
-        WNDPROC old_proc = (WNDPROC)SetWindowLongPtrA( WIN_Handle32(hwnd), offset, (LONG_PTR)new_proc );
+        WNDPROC old_proc = (WNDPROC)SetWindowLongPtrA( hwnd, offset, (LONG_PTR)new_proc );
         return (LONG)WINPROC_GetProc16( old_proc, FALSE );
     }
-    else return SetWindowLongA( WIN_Handle32(hwnd), offset, newval );
+    else return SetWindowLongA( hwnd, offset, newval );
 }
 
 




More information about the wine-cvs mailing list