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

Date: 2010jan24 Update: 2024dec31 Product: Microsoft Visual Studio Language: C++ Q. C++: 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 *pApp; if ((pApp = AfxGetApp()) == NULL) return NULL; return pApp->m_pMainWnd; }