0024088: Unsafe window handle management in Draw using GetWindowLong
authoromy <omy@opencascade.com>
Thu, 16 Jan 2014 08:16:56 +0000 (12:16 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 16 Jan 2014 08:18:14 +0000 (12:18 +0400)
Replaced Get-/SetWindowLong with Get-/SetWindowLongPtr in files of TKDraw.

Reverted the unrelated changes

src/Draw/CommandWindow.cxx
src/Draw/Draw_Window.cxx
src/Draw/MainWindow.cxx
src/Draw/init.cxx

index 39d8946..93a9d8a 100644 (file)
 HWND CreateCommandWindow(HWND hWnd, int /*nitem*/)
 {
   HINSTANCE       hInstance;
-  
-#ifndef _WIN64
-  hInstance = (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
-#else
-  hInstance = (HINSTANCE)GetWindowLong(hWnd,GWLP_HINSTANCE);
-#endif
+  hInstance = (HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE);
+
        HWND hWndCommand = (CreateWindow(COMMANDCLASS, COMMANDTITLE,
                                                                                                                        WS_CLIPCHILDREN | WS_OVERLAPPED |
                                                                                                                        WS_THICKFRAME | WS_CAPTION      ,
@@ -83,7 +79,7 @@ LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam
   {
     case WM_CREATE :
                                        CommandCreateProc(hWnd);
-                                       hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
+                                       hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND);
                                        SendMessage(hWndEdit,EM_REPLACESEL, 0,(LPARAM)PROMPT);
                                        break;
 
@@ -95,7 +91,7 @@ LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam
 
     case WM_SIZE :
     {
-                       hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);          
+                       hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND);          
                        MoveWindow(hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
           // Place the cursor at the end of the buffer
           // Nb of characters in the buffer of hWndEdit
@@ -105,7 +101,7 @@ LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam
     }
 
     case WM_SETFOCUS :
-                       hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
+                       hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND);
           SetFocus(hWndEdit);
           break;
 
@@ -124,11 +120,8 @@ LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM);
 BOOL CommandCreateProc(HWND hWnd)
 {
 
-#ifndef _WIN64
-  HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
-#else
-  HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWLP_HINSTANCE);
-#endif
+  HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
+
   HWND hWndEdit = CreateWindow("EDIT",NULL,
                          WS_CHILD | WS_VISIBLE | WS_VSCROLL |
                          ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
@@ -138,26 +131,19 @@ BOOL CommandCreateProc(HWND hWnd)
 
     // Save hWndEdit in the extra memory in 0 of CommandWindow
   if (hWndEdit)
-    SetWindowLong(hWnd, CLIENTWND, (LONG)hWndEdit);
+    SetWindowLongPtr(hWnd, CLIENTWND, (LONG_PTR)hWndEdit);
 
     // Sub-Class of the window
     //-------
     // Save the pointer on the existing procedure
   #ifdef STRICT
-   #ifndef _WIN64
-    OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
-   #else
-    OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWLP_WNDPROC);
-   #endif // _WIN64
+    OldEditProc = (WNDPROC)GetWindowLongPtr(hWndEdit, GWLP_WNDPROC);
   #else
-    OldEditProc = (FARPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
+    OldEditProc = (FARPROC)GetWindowLongPtr(hWndEdit, GWLP_WNDPROC);
   #endif
     // Implement the new function
-#ifndef _WIN64
-  SetWindowLong(hWndEdit, GWL_WNDPROC, (LONG) EditProc);
-#else
-  SetWindowLong(hWndEdit, GWLP_WNDPROC, (LONG) EditProc);
-#endif
+  SetWindowLongPtr(hWndEdit, GWLP_WNDPROC, (LONG_PTR) EditProc);
+
   return(TRUE);
 }
 
index 40aced3..7a76757 100644 (file)
@@ -1353,11 +1353,7 @@ HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem)
   }
   else {
     HANDLE hInstance;
-#ifndef _WIN64
-    hInstance = (HANDLE)GetWindowLong(hWndClient,GWL_HINSTANCE);
-#else
-    hInstance = (HANDLE)GetWindowLong(hWndClient,GWLP_HINSTANCE);
-#endif
+    hInstance = (HANDLE)GetWindowLongPtr(hWndClient,GWLP_HINSTANCE);
 
     return CreateMDIWindow(DRAWCLASS, DRAWTITLE,
                            WS_CAPTION | WS_CHILD | WS_THICKFRAME,
@@ -1372,7 +1368,7 @@ HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem)
 \*--------------------------------------------------------*/
 LRESULT APIENTRY DrawWindow::DrawProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
 {
-  DrawWindow* localObjet = (DrawWindow*)GetWindowLong(hWnd, CLIENTWND);
+  DrawWindow* localObjet = (DrawWindow*)GetWindowLongPtr(hWnd, CLIENTWND);
   if (!localObjet)
     {
       if (Draw_IsConsoleSubsystem)
@@ -1514,7 +1510,7 @@ void DrawWindow::Init(Standard_Integer theXLeft, Standard_Integer theYTop,
   SetPosition  (aRect.left, aRect.top);
   SetDimension (aRect.right - aRect.left, aRect.bottom - aRect.top);
   // Save the pointer at the instance associated to the window
-  SetWindowLong(win, CLIENTWND, (LONG)this);
+  SetWindowLongPtr(win, CLIENTWND, (LONG_PTR)this);
   HDC hDC = GetDC(win);
   SetBkColor(hDC, RGB(0, 0, 0));
   myCurrPen  = 3;
index 140734f..3645195 100644 (file)
@@ -41,7 +41,7 @@ LRESULT APIENTRY WndProc(HWND hWndFrame, UINT wMsg, WPARAM wParam, LPARAM lParam
     case WM_CREATE :
       {
        CreateProc(hWndFrame);                                  
-       hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND);
+       hWndClient = (HWND)GetWindowLongPtr(hWndFrame, CLIENTWND);
        DrawWindow::hWndClientMDI = hWndClient;
        if (!Draw_IsConsoleSubsystem)
          CreateCommandWindow(hWndFrame,0);                                     
@@ -58,7 +58,7 @@ LRESULT APIENTRY WndProc(HWND hWndFrame, UINT wMsg, WPARAM wParam, LPARAM lParam
       break;
 
     default :
-      hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND);
+      hWndClient = (HWND)GetWindowLongPtr(hWndFrame, CLIENTWND);
       return(DefFrameProc(hWndFrame, hWndClient, wMsg, wParam, lParam));
   }
   return(0l);
@@ -76,7 +76,7 @@ BOOL CreateProc(HWND hWndFrame)
   if (hWnd != NULL)
   {
     // Save hWnd in the main window in extra memory in 0
-    SetWindowLong(hWndFrame, CLIENTWND, (LONG)hWnd);
+    SetWindowLongPtr(hWndFrame, CLIENTWND, (LONG_PTR)hWnd);
   }
   return(TRUE);
 }
@@ -90,7 +90,7 @@ BOOL CreateProc(HWND hWndFrame)
 BOOL CommandProc(HWND hWndFrame, WPARAM wParam, LPARAM /*lParam*/)
 {
   // Handle on window MDI
-  HWND hWndClient = (HWND)GetWindowLong (hWndFrame, CLIENTWND);
+  HWND hWndClient = (HWND)GetWindowLongPtr (hWndFrame, CLIENTWND);
   switch (LOWORD(wParam))
        {
          case IDM_WINDOW_NEXT :
@@ -134,11 +134,8 @@ BOOL CommandProc(HWND hWndFrame, WPARAM wParam, LPARAM /*lParam*/)
 \*--------------------------------------------------------------------------*/
 VOID DestroyProc(HWND hWnd)
 {
-#ifndef _WIN64
-  HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
-#else
-  HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd, GWLP_HINSTANCE);
-#endif
+  HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
+
   Destroy_Appli(hInst);
   PostQuitMessage(0);
 }
index 9a2f823..946e9ca 100644 (file)
@@ -136,11 +136,7 @@ HWND CreateMDIClientWindow(HWND hWndFrame)
   ccs.hWindowMenu = NULL;
   ccs.idFirstChild = 0;
 
-#ifndef _WIN64
-  hInstance = (HANDLE)GetWindowLong(hWndFrame, GWL_HINSTANCE);
-#else
-  hInstance = (HANDLE)GetWindowLong(hWndFrame, GWLP_HINSTANCE);
-#endif
+  hInstance = (HANDLE)GetWindowLongPtr(hWndFrame, GWLP_HINSTANCE);
 
   hWndClient = CreateWindow("MDICLIENT",NULL,
                                                                                                WS_CHILD | WS_CLIPSIBLINGS |