Locate implementation of a particular Dialog in huge Codebase Easily.

7 04 2008


Huge Maintenance projects usually contain a number of dialogs. Sometimes we want to modify a particular dialog in that project. During most of the case, we might be encountering that dialog for the first time( Guys digging old code base like me can understand it very well ). At that time, what usually people do to locate the dialog implementation is as follows.

  1. Iterate through all dialogs in the resource by opening it or by checking the dialog ids.
  2. Find the matching dialog.
  3. Take the dialog ID.
  4. Search the code base for reference to the Dialog ID.
  5. You found it!

If your code base have 100eds of dialogs, how much time will it take?


All dialogs have the same base class, CDialog. So the CDialog constructor will be called before the constructor of your dialog class get called. Now follow the steps.

  1. Start debugging your project by F5.
  2. Open the file – <VisualStudioDir>\VC98\MFC\SRC\DLGCORE.CPP
  3. Put breakpoints on all CDialog constructors. Note – there are many overloads for your CDialog constructor. Since its unknown how your dialog class is initialized, its better to put break points on all CDialog constructors.
  4. Now launch your dialog from your application and the debugger will break on the CDialog constructor.
  5. Now take the Call Stack by pressing Alt + 7.
  6. From the call stack you can identify the class you were searching.


The above steps only works for debug version. If you are in release version, then breakpoint at DLGCORE.CPP will be disabled at the starting itself. For that, see following steps.

1) Our problem is how to put breakpoint at CDialog in release build.
2) For that take any put any other dialog class in your workspace and put a breakpoint in its constructor and start debug by F5.
3) when the breakpoint at your dialog’s constructor is reached, right click and select “Go To Disassembly”. It will be as follows.

62:   CDlg1Dlg::CDlg1Dlg(CWnd* pParent /*=NULL*/)
63:       : CDialog(CDlg1Dlg::IDD, pParent)
64:   {
00401216   push        ebp
00401217   mov         ebp,esp
00401219   push        0FFh
0040121B   push        offset $L87331 (00401d29)
00401220   mov         eax,fs:[00000000]
00401226   push        eax
00401227   mov         dword ptr fs:[0],esp
0040122E   push        ecx
0040122F   mov         dword ptr [ebp-10h],ecx
00401232   mov         eax,dword ptr [pParent]
00401235   push        eax
00401236   push        66h
00401238   mov         ecx,dword ptr [this]
0040123B   call        CDialog::CDialog (00401a0a)
00401240   mov         dword ptr [ebp-4],0

4) From the disassembly you will get the address of CDialog constructor to be called.
5) now take the breakpoint window by pressing Ctrl+B.

6) Just add a breakpoint by specifying this memory location in “Break At” editbox. don’t forget to add 0x in front of memory location. here it will be 0x00401a0a.
7) Now you’ve successfully added a break point at CDialog constructor in release version too. Enable it only when you need it.


Targeted Audience – Beginners.

Advertisements