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?
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
orWM_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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With