Remove "->m_pMainWnd" and it should work. You were trying to get the main window and cast it ta an application object. That's why it chrashes.