3

I have an MFC dialog based application created inside Visual Studio 2008.

CCalendarWindowDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();

When I run the application, DoModal() asserts at very first line

INT_PTR CDialog::DoModal()
{
    // can be constructed with a resource template or InitModalIndirect
    ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
    m_lpDialogTemplate != NULL);
}

Can anyone please help?

user196614
  • 243
  • 1
  • 6
  • 15

3 Answers3

3

For solving this in the Constructor of my Dialog class, I did something like

CCalendarWindowDlg::CCalendarWindowDlg ()
    :CDialog(IDD)
{
}

Notice I am calling the constructor of the CDialog parent class with the resource ID of the form I want to present.

sergiol
  • 4,122
  • 4
  • 47
  • 81
1

I had the same problem when just creating new dialog based MFC application using Visual Studio 2012. For me the solution was to use dialog construtor that takes dialog resource ID as parameter.

For instance:

CCalendarWindowDlg dlg(IDD_MYDIALOG);
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();

Hope this helps.

1

Seems like the resource template is missing or wrongly mapped.

Look at the IDD attribute at your CCalendarWindowDlg class and see whether you have the appropriate dialog present in the Resource View.

Are you using the satellite DLLs for localization or other purpose? or the CCalendarWindowDlg component resource DLL might be missing.

  • Thanks Gopalakrishnan for your prompt reply. But I have checked the IDD attribute and it matches with the one in "resource.h" and "CalendarWindow.rc". What else can I do? – user196614 Jan 11 '10 at 10:10
  • you can see whether CCalenderWindowDlg uses a satellite DLL –  Jan 12 '10 at 03:23