Visual C++ 2005 Professional Debug/Win32 Windows 7 Enterprise 64-bit
I set a breakpoint at my program's entrypoint. My program crashes before reaching that breakpoint. When the unhandled exception occurs (Access violation reading location 0x00000000.), I click on Break, and set a breakpoint where the current instruction pointer is located. Restart the debugging session and the program stops on the new breakpoint. I scroll up to the top of the current function, __tmainCRTStartup(), and set a breakpoint at the opening brace for the function.
I stop/restart the debugger again, this time stopping at __tmainCRTStartup(). By this time, all of the DLL's have been loaded, and if they needed to, run their load functions. Press [F5] to run to the original breakpoint. The Next Statement pointer is pointing at a call to WinMain(...).
Stepping over this statement causes the unhandled exception. Stepping into the statement takes me to this statement: "return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);". Stepping into once again takes me to the Disassembly window, where I see the next statement to run: "jmp AfxWinMain (563AFAh)".
I can step through the assembly code, but I cannot make out what it is trying to do before it tries to dereference a pointer in one of the registers, which holds a value of zero (0).
I read another post about a C program crashing before reaching main(). Even though tagged with "C", many responders mentioned constructors of a static instance of a class being a possible culprit. Others mentioned DLL's loading and running their own startup code that might crash the program, but the DLL's all seem to load and I have evidence of at least one DLL running its startup code, before the program gets to __tmainCRTSetup() .
Can anyone help me understand this? Knowing why it's doing this should help me understand how to fix it.
Thank you!