Hey,

It works even if it placed before instantiating the dialog. Here is my code:
...
AfxMessageBox("hi");
CDlgtestDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
...

By that time I am calling msg box, m_pMainWnd is null because it's nothing but the handle to the dialog object. Even I am surprised to see this working.. Can u tell me why?

Regards,
Rangaraya Sharma.