Reasons Why RegisterClass() and CreateWindow() Fail

Last reviewed: November 2, 1995
Article ID: Q65257
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.0 and 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

The RegisterClass() and CreateWindow() functions fail when the system resources are used up. The percentage of free system resources reflects the amount of available space in the USER and GDI heaps within Windows. The smaller amount of free space is reported in the Program Manager's About box because if either heap fills up, functions fail.

Under Windows NT, the USER and GDI heap resources are practically unlimited. Under Windows 95, the USER and GDI heap resources are greater than Windows 3.1, but not as great as under Windows NT.

MORE INFORMATION

If the amount of free system resources remains low after the application is exited, it is more likely that the GDI heap is filling. The main reason for the GDI heap filling is that GDI objects that are created by the application are not deleted or destroyed when they are no longer needed, or when the program terminates. Windows does not delete GDI objects (pens, brushes, fonts, regions, and bitmaps) when the program exits. Objects must be properly deleted or destroyed.

NOTE: Win32-based applications cannot cause the USER or GDI heaps to overflow when they terminate, because the system will release the resources to maximize available resources.

The following are two situations that can cause the USER heap to get full:

  1. Memory is allocated for "extra bytes" associated with window classes and windows themselves. Make sure that the cbClsExtra and cbWndExtra fields in the WNDCLASS structure are set to 0 (zero), unless they really are being used.

  2. Menus are stored in the USER heap. If menus are added but are not destroyed when they are no longer needed, or when the application terminates, system resources will go down.

CreateWindow() will also fail under the following conditions:

  1. Windows cannot find the window procedure listed in the CreateWindow() call. Avoid this by ensuring that each window procedure is listed in the EXPORTS section of the program's DEF file.

  2. CreateWindow() cannot find the specified window class.

  3. The hwndparent is incorrect (make sure to use debug Windows to see the RIPs).

  4. CreateWindow() cannot allocate memory for internal structures in USER heap.

  5. The application returns 0 (zero) to the WM_NCCREATE message.

  6. The application returns -1 to the WM_CREATE message.


Additional reference words: 3.00 3.10 3.50 4.00
KBCategory: kbui
KBSubcategory: UsrWndw


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: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.