Dave's Brain

Browse - programming tips - afxgetmainwnd returns null

Date: 2010jan24
Product: Visual Studio

Q.  AfxGetMainWnd() is returning NULL.  What can I do about this?

A.  Apparently it turns NULL when called from a thread other than the main one.
Which mains 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;
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.