Wednesday, December 24, 2008

[VC++] Debugging application startup

1. Consider your application is being launched from some other applications and you want to debug the same then how you can do that ?

First of all your module should be made debuggable by building with proper project settings (making release build debuggable). Now start your application, since application is started by some other parent application you cannot get the debug mode.
So what you need to do is that,
a). Take taskmanager->Process tab & Right click the entry corresponding to your process
b). Choose the Debug menu item and press Yes for the warning message shown
c). Visual Studio Debugger will be launched, take File->Open & choose the file which you want to insert break point
d). Insert break point where ever needed and execute it will work fine !

2. Now the question is - How can you debug your application (if lanched by some other process) in the start up, say you want to debug App class constructor or InitInstance() ?
Some of you might have faced the same situation and you would have gone behind putting MessageBox() in some startup function, but there is a better option for the same.
What you need to do for debugging in the startup is
a). Set Auto flag to '1' under registery entry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug
b). Add any of the below lines where you want to debug in start up,
_asm int 3;
or
DebugBreak();
Now try start your application, it will automatically launch msdev for debugging and break the execution where you put _asm int 3 or DebugBreak.

No comments: