When CDialog.DoModal() function fails to create dialog box?

11,434

DoModal() relies on the CreateDialogIndirect() API function. The documentation for its cousin DialogBox() states that function can fail under the following circumstances:

  • an invalid parameter value,
  • the system class was registered by a different module,
  • the WH_CBT hook is installed and returns a failure code,
  • one of the controls in the dialog template is not registered, or its window procedure fails on WM_CREATE or WM_NCCREATE.

I personally never encountered the first three reasons, but I was bitten once by the fourth because my dialog box contained an ActiveX control that was not registered on the machine. Maybe you're experiencing the same issue.

Share:
11,434
Cary
Author by

Cary

A learning software craftsman and occasional writer. Interested in: Enterprise application architecture design; Garbage collection in Java virtual machine; Agile enthusiast;

Updated on June 11, 2022

Comments

  • Cary
    Cary almost 2 years

    MSDN said, for the CDialog.DoModal() function, the return value is –1 if the function could not create the dialog box. It does not say in which case it could fail to create the dialog box.

    A quick investigation into MFC source code shows if the (LPCDLGTEMPLATE)LockResource(hDialogTemplate) returns NULL, the DoModal function could return -1.

    Since my problem cannot be reproduced stably in our stress test, I cannot debug the program to find the root cause. Did anybody here meet similar problem?