That's because AFXMessageBox reflies on the main window to produce the message box. It basically does this -> MessageBox(AfxGetMainWnd(),text,...); Since you place the AfxMessageBox after the DoModal(), the AfxGetMainWnd() will return a bad CWnd, since the dialog box is closed and destroyed. Just use a MessageBox(NULL,text,...); to do your box