Posts Tagged ‘NULL’

Weird problem with AfxWinMain()

Wednesday, January 27th, 2010

I spent the last hours hunting down a weird crash problem in AfxWinMain(). It’s the init function in an MFC application that gets called before anything else.

And it crashes at “if (!pThread->InitInstance())” because AfxGetThread() returned a NULL pointer.

The problem was paired with link errors that vanished when the buid was repeated. Since this is “normal” with MS C++ (I’ve seen that problem often before), I didn’t really notice it.

As it turns out the entire code was correct. I imported it into a new project and it worked. Comparing the the vcproj-Files I found the line that made all the difference. Removing this line suddenly fixed my problem:


(in Configuration > Tool Name=”VCCLCompilerTool”).