PRB: RegisterClass()/ClassEx() Fails If cbWndExtra > 40 Bytes

Last reviewed: September 29, 1995
Article ID: Q131288
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows 95 version 4.0
    

SYMPTOMS

Under Windows 95, a call to RegisterClass() or RegisterClassEx() returns NULL if a value greater than 40 is specified for the cbWndExtra or cbClsExtra members of the WNDCLASS or WNDCLASSEX structure.

CAUSE

Windows 95 checks to see if cbWndExtra or cbClsExtra is greater than 40. If so, it outputs these debug messages and returns NULL to indicate failure:

   RegisterClassEx: Unusually large cbClsExtra (>40)
   RegisterClassEx: Unusually large cbWndExtra (>40)

RESOLUTION

If more than 40 bytes are needed to store window-specific or class-specific information, an application should allocate memory. Then set the cbWndExtra or cbClsExtra to 4 bytes, and pass the pointer to the allocated memory by using SetClassLong() as follows:

   SetClassLong (hWnd, GCL_CBCLSEXTRA, lpMemoryAllocated);
   SetClassLong (hWnd, GCL_CBWNDEXTRA, lpMemoryAllocated);

The pointer can then be retrieved when needed by using GetClassLong() as follows:

   lpMemoryAllocated = GetClassLong (hWnd, GCL_CBCLSEXTRA);
   lpMemoryAllocated = GetClassLong (hWnd, GCL_CBWNDEXTRA);

STATUS

This behavior is by design. However, as of version 3.51, Windows NT does not have this 40-byte limitation.


Additional reference words: 4.00
KBCategory: kbui kbprb
KBSubcategory: UsrCls


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.