Ignore:
Timestamp:
Feb 22, 2001, 11:37:31 AM (25 years ago)
Author:
sandervl
Message:

window & class user word access fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/win32class.cpp

    r5084 r5242  
    1 /* $Id: win32class.cpp,v 1.22 2001-02-10 10:35:31 sandervl Exp $ */
     1/* $Id: win32class.cpp,v 1.23 2001-02-22 10:37:30 sandervl Exp $ */
    22/*
    33 * Win32 Window Class Managment Code for OS/2
     
    104104  dprintf(("USER32:  wndclass->hIconSm %X\n", wndclass->hIconSm));
    105105
    106   nrExtraClassWords     = wndclass->cbClsExtra;
    107   nrExtraWindowWords    = wndclass->cbWndExtra;
     106  nrExtraClassBytes     = wndclass->cbClsExtra;
     107  nrExtraWindowBytes    = wndclass->cbWndExtra;
    108108  backgroundBrush       = wndclass->hbrBackground;
    109109  hCursor               = wndclass->hCursor;
     
    123123
    124124  //User data class words/longs
    125   if(nrExtraClassWords) {
    126         userClassLong = (ULONG *)_smalloc(nrExtraClassWords);
    127         if(userClassLong == NULL) {
    128                 dprintf(("Win32Class ctr: userClassLong == NULL!"));
     125  if(nrExtraClassBytes) {
     126        userClassBytes = (char *)_smalloc(nrExtraClassBytes);
     127        if(userClassBytes == NULL) {
     128                dprintf(("Win32Class ctr: userClassBytes == NULL!"));
    129129                exit(1);
    130130        }
    131         memset(userClassLong, 0, nrExtraClassWords);
    132   }
    133   else  userClassLong = NULL;
     131        memset(userClassBytes, 0, nrExtraClassBytes);
     132  }
     133  else  userClassBytes = NULL;
    134134
    135135  cWindows = 0;
     
    151151  WINPROC_FreeProc(windowProc, WIN_PROC_CLASS);
    152152
    153   if(userClassLong)     free(userClassLong);
     153  if(userClassBytes)    free(userClassBytes);
    154154  if(classNameA)        free(classNameA);
    155155  if(classNameW)        free(classNameW);
     
    251251
    252252  if(HIWORD(id)) {
    253         lpszClassName = UnicodeToAsciiString((LPWSTR)id);
    254   }
    255   else  lpszClassName = (LPSTR)id;
     253    lpszClassName = UnicodeToAsciiString((LPWSTR)id);
     254  }
     255  else  lpszClassName = (LPSTR)id;
    256256
    257257  winclass = FindClass(hInstance, lpszClassName);
     
    278278BOOL Win32WndClass::getClassInfo(WNDCLASSEXA *wndclass)
    279279{
    280   wndclass->cbClsExtra    = nrExtraClassWords;
    281   wndclass->cbWndExtra    = nrExtraWindowWords;
     280  wndclass->cbClsExtra    = nrExtraClassBytes;
     281  wndclass->cbWndExtra    = nrExtraWindowBytes;
    282282  wndclass->hbrBackground = backgroundBrush;
    283283  wndclass->hCursor       = hCursor;
     
    295295BOOL Win32WndClass::getClassInfo(WNDCLASSEXW *wndclass)
    296296{
    297   wndclass->cbClsExtra    = nrExtraClassWords;
    298   wndclass->cbWndExtra    = nrExtraWindowWords;
     297  wndclass->cbClsExtra    = nrExtraClassBytes;
     298  wndclass->cbWndExtra    = nrExtraWindowBytes;
    299299  wndclass->hbrBackground = backgroundBrush;
    300300  wndclass->hCursor       = hCursor;
     
    376376  switch(index) {
    377377        case GCL_CBCLSEXTRA:
    378                 return nrExtraClassWords;
     378                return nrExtraClassBytes;
    379379        case GCL_CBWNDEXTRA:
    380                 return nrExtraWindowWords;
     380                return nrExtraWindowBytes;
    381381        case GCL_HBRBACKGROUND:
    382382                return backgroundBrush;
     
    399399                return 0;
    400400        default:
    401                 if(index > 0 && index < nrExtraClassWords - sizeof(ULONG)) {
    402                         return userClassLong[index];
    403                 }
     401                if(index >= 0 && index + sizeof(ULONG) <= nrExtraClassBytes) {
     402                        //Note: NT4, SP6 does not set the last error to 0
     403                        SetLastError(ERROR_SUCCESS);
     404                        return *(ULONG *)(userClassBytes + index);
     405                }
     406                if(classNameA) {
     407                     dprintf2(("WARNING: getClassLong %s: %d -> wrong INDEX", classNameA, index));
     408                }
     409                else dprintf2(("WARNING: getClassLong %d: %d -> wrong INDEX", classAtom, index));
    404410                SetLastError(ERROR_INVALID_INDEX);  //verified in NT4, SP6
    405411                return 0;
     
    414420                return (WORD)classAtom;
    415421        default:
    416                 if(index > 0 && index < nrExtraClassWords - sizeof(WORD)) {
    417                         return ((WORD *)userClassLong)[index];
    418                 }
     422                if(index >= 0 && index + sizeof(WORD) <= nrExtraClassBytes) {
     423                        //Note: NT4, SP6 does not set the last error to 0
     424                        SetLastError(ERROR_SUCCESS);
     425                        return *(WORD *)(userClassBytes + index);
     426                }
     427                if(classNameA) {
     428                     dprintf2(("WARNING: getClassWord %s: %d -> wrong INDEX", classNameA, index));
     429                }
     430                else dprintf2(("WARNING: getClassWord %d: %d -> wrong INDEX", classAtom, index));
    419431                SetLastError(ERROR_INVALID_INDEX);  //verified in NT4, SP6
    420432                return 0;
     
    430442  switch(index) {
    431443        case GCL_CBCLSEXTRA: //TODO (doesn't affect allocated classes, so what does it do?)
    432                 rc = nrExtraClassWords;
    433 //              nrExtraClassWords = lNewVal;
     444                rc = nrExtraClassBytes;
     445//              nrExtraClassBytes = lNewVal;
    434446                break;
    435447        case GCL_CBWNDEXTRA:
    436                 rc = nrExtraWindowWords;
    437                 nrExtraWindowWords = lNewVal;
     448                rc = nrExtraWindowBytes;
     449                nrExtraWindowBytes = lNewVal;
    438450                break;
    439451        case GCL_HBRBACKGROUND:
     
    466478                break;
    467479        case GCL_WNDPROC:
    468                 //Note: Type of SetWindowLong determines new window proc type
     480                //Note: Type of SetWindowLong determines new window proc type
    469481                //      UNLESS the new window proc has already been registered
    470482                //      (use the old type in that case)
    471483                //      (VERIFIED in NT 4, SP6)
    472                 //TODO: Is that also true for GCL_WNDPROC???????????????
     484                //TODO: Is that also true for GCL_WNDPROC???????????????
    473485                rc = (LONG)WINPROC_GetProc(windowProc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A );
    474486                WINPROC_SetProc((HWINDOWPROC *)&windowProc, (WNDPROC)lNewVal, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_CLASS );
     
    478490                return 0;
    479491        default:
    480                 if(index > 0 && index < nrExtraClassWords - sizeof(ULONG)) {
    481                         rc = userClassLong[index];
    482                         userClassLong[index] = lNewVal;
     492                if(index >= 0 && index + sizeof(ULONG) <= nrExtraClassBytes) {
     493                        rc = *(ULONG *)(userClassBytes + index);
     494                        *(ULONG *)(userClassBytes + index) = lNewVal;
    483495                        break;
    484496                }
    485497                SetLastError(ERROR_INVALID_INDEX);  //verified in NT4, SP6
    486                 if(classNameA) {
    487                       dprintf2(("WARNING: Win32WndClass::setClassLongA %s: %d %x -> wrong INDEX", classNameA, index, lNewVal));
    488                 }
    489                 else dprintf2(("WARNING: Win32WndClass::setClassLongA %d: %d %x -> wrong INDEX", classAtom, index, lNewVal));
     498                if(classNameA) {
     499                     dprintf2(("WARNING: Win32WndClass::setClassLongA %s: %d %x -> wrong INDEX", classNameA, index, lNewVal));
     500                }
     501                else dprintf2(("WARNING: Win32WndClass::setClassLongA %d: %d %x -> wrong INDEX", classAtom, index, lNewVal));
    490502                return 0;
    491503  }
     
    509521                return(rc);
    510522        default:
    511                 if(index > 0 && index < nrExtraClassWords - sizeof(WORD)) {
    512                         rc = ((WORD *)userClassLong)[index];
    513                         ((WORD *)userClassLong)[index] = wNewVal;
     523                if(index >= 0 && index + sizeof(WORD) <= nrExtraClassBytes) {
     524                        rc = *(WORD *)(userClassBytes + index);
     525                        *(WORD *)(userClassBytes + index) = wNewVal;
     526                        //Note: NT4, SP6 does not set the last error to 0
     527                        SetLastError(ERROR_SUCCESS);
    514528                        return(rc);
    515529                }
    516530                SetLastError(ERROR_INVALID_INDEX);  //verified in NT4, SP6
     531                if(classNameA) {
     532                     dprintf2(("WARNING: setClassWord %s: %d %x -> wrong INDEX", classNameA, index, wNewVal));
     533                }
     534                else dprintf2(("WARNING: setClassWord %d: %d %x -> wrong INDEX", classAtom, index, wNewVal));
    517535                return 0;
    518536  }
Note: See TracChangeset for help on using the changeset viewer.