INF: Possible Causes of Dialog Box Creation Failure

ID Number: Q80843

3.00

WINDOWS

Summary :

The dialog box creation routines (CreateDialog, CreateDialogParam,

CreateDialogIndirect, CreateDialogIndirectParam, DialogBox,

DialogBoxParam, DialogBoxIndirect, and DialogBoxIndirectParam) can

fail for several reasons. When one of these functions fails, the

dialog box is not displayed on the screen. Of the causes for dialog

box creation failure, this article discusses eight, which are listed

below, and provides a resolution or explanation:

1. Application runs out of file handles.

2. One or more text strings in a dialog resource starts with the

character represented by the value 255 (0xFF).

3. Several small compiled resource (RES) files are combined using the

MS-DOS command "COPY /b".

4. A dialog box with an edit control cannot be created when at least

ten dialog boxes, each with one or more edit controls, are open

simultaneously.

5. The dialog resource is not included in the RC file.

6. Insufficient system resources.

7. In a dialog registered with a private dialog class, the dialog

procedure does not return the value returned from DefDlgProc as its

return value.

8. Wrong HINSTANCE value used.

More Information:

The order in which the causes are listed below does not provide any

indication of how often each cause occurs.

Cause 1: Application runs out of file handles.

Resolution 1: Use the SetHandleCount() function to open more file

handles. For more information on this procedure, query this knowledge

base on the words:

prod(winsdk) and resources and SetHandleCount

Explanation 1: Windows requires a file handle to load a resource.

Because each dialog box creation routine loads dialog resources, an

application must have at least one file handle available for that

purpose.

Cause 2: One or more text strings in a dialog resource start with the

character represented by the value 255 (0xFF).

Resolution 2: For an explanation of two methods to work around this

cause, query this knowledge base on the words:

prod(winsdk) and string and resource and 255

Explanation 2: Windows uses the number 255 to indicate that a resource

is represented by an ordinal value instead of by a string name. During

the process of parsing the resource that contains one of these

characters, Windows incorrectly skips the next two bytes and treats

the new position in the resource as the next piece of data.

Cause 3: Several small compiled resource (RES) files are combined

using the MS-DOS command "COPY /b".

Resolution 3: Use the #include directive to combine the files at the

source level. If the Windows Resource Compiler cannot handle the large

RC file, consider storing the resources in a resource-only DLL. For

more information, query this knowledge base on the words:

prod(winsdk) and combined and res

Explanation 3: The Resource Compiler shipped with version 3.0 of the

Windows Software Development Kit (SDK) has been enhanced to handle

resource files much larger than its Windows 2.x counterpart. The

format of the compiled resource files in Windows 3.0 does not support

concatenation of RES files.

Cause 4: A dialog box with an edit control cannot be created when at

least ten dialog boxes, each with one or more edit controls, are open

simultaneously.

Resolution 4: Specify the DS_LOCALEDIT style in the dialog box

template, or create the edit control explicitly with the CreateWindow

function.

Explanation 4: For more information, query this knowledge base on the

words:

prod(winsdk) and dialog and GlobalAlloc and fails

Cause 5: The dialog resource is not included in the RC file.

Resolution 5: Use RCINCLUDE to include the dialog resource in the RC

file.

Explanation 5: Include the DLG file created by the Dialog Editor into

the RC file so the Resource Compiler can add the dialog resource to

the executable file.

Cause 6: Insufficient system resources.

Resolution 6: Verify that system resources are not lost because an

application does not delete objects that it creates. For more

information, query this knowledge base on the words:

prod(winsdk) and lost and heapwalk

The article "Careful Windows Resource Allocation and Cleanup Improves

Application Hygiene," in the September 1991 issue of the "Microsoft

Systems Journal" discusses this issue further.

Explanation 6: Unless each application frees all the resources that it

allocates, eventually Windows does not have enough memory to create

the controls and/or the dialog box itself.

Cause 7: In a dialog registered with a private dialog class, the

dialog procedure does not return the value returned from DefDlgProc as

its return value.

Resolution 7: Whenever the private-class dialog procedure passes an

unprocessed message to DefDlgProc, the dialog procedure must propagate

the value returned by DefDlgProc.

Explanation 7: When a private-class dialog procedure passes an

unprocessed message to DefDlgProc, it must return the value returned

from DefDlgProc. This behavior differs from that of a default-class

dialog procedure, which usually returns FALSE outside the message

switch when it does not process a message. If a private-class dialog

procedure is implemented in this way, and the procedure does not

process the WM_NCCREATE message, it will return FALSE. The

CreateWindow function sends the WM_NCCREATE message to create the non-

client area of the dialog window. CreateWindow treats a response of

FALSE from the dialog procedure as failure and returns a NULL handle

to the application.

Cause 8: Wrong HINSTANCE value used.

Resolution 8: Specify the application's instance handle.

Explanation 8: The dialog box creation routine must specify the

application's instance because the dialog template is stored in the

application instance.

Additional reference words: fails modal modeless