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



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • Microsoft Windows 95

This article was previously published under Q131288

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.

Modification Type:MinorLast Reviewed:5/1/2004
Keywords:kbprb kbWndw kbWndwClass KB131288