Programming Tips - AfxGetMainWnd() is returning NULL. What can I do about this?

Date: 2010jan24 Product: Visual Studio Language: C/C++ Q. AfxGetMainWnd() is returning NULL. What can I do about this? A. Apparently it returns NULL when called from a thread other than the main one. Which means its not very useful. Before Visual Studio 2005 it worked fine. Use this function instead:
inline CWnd *MyGetMainWnd() { CWinApp *app; if ((app = AfxGetApp()) == NULL) return NULL; return app->m_pMainWnd; }