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

ID: Q131288

The information in this article applies to:

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 query words:

Keywords          : kbGrpUser kbWinOS95 kbWndw kbWndwClass 
Issue type        : kbprb

Last Reviewed: December 26, 1998