Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 869
Cary Avatar asked Mar 14 '12 13:03

Cary


1 Answers

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.

like image 129
Frédéric Hamidi Avatar answered Nov 07 '22 20:11

Frédéric Hamidi