Click here to Skip to main content
15,881,898 members
Articles / Desktop Programming / MFC

Remote Debugging in MSVC++ 6.0 - Step by step in the OnPaint message handler

Rate me:
Please Sign up or sign in to vote.
4.73/5 (20 votes)
24 Jan 20024 min read 256K   1.4K   88   39
This article how to setup the remote debugging capatibilities of Visual C++ 6.0. With just a few steps and an extra machine (of course!) I´ll show how can you step into the OnPaint message handler.

Introduction

Most of the developers that work with graphic applications or work with applications that have full-screen window sometimes need to know exactly what is going on behind the OnPaint function or any other screen-drawing function. The problem is that when you set up a break point in the OnPaint message handler, the focus of the window goes to the VC++ environment. When this happens, your onpaint event is lost and you can't even see what's happening during the painting process. This situation is very common in directX programming too, where the program needs to use fullscreen mode and doesn't allow you to switch to VC++.

MS VC++ has a workaround to this problem called remote debugger. The remote debugger enables you to execute your app in one machine while you step into the code in another machine.

To explain how this VC++ feature works, we are going to use the sample project provided with this article.

Setting Up the Environment

The first thing you need to do is install the remote debugger in the remote machine. If you don't have VC++ installed in the remote machine (it's not required :) ), you need to copy the following files to the system directory of the remote computer:

MFC42D.DLL
MFCO42D.DLL
MSVCRTD.DLL

After copying these files, you need to establish a connection between the remote computer and the "host" computer (we'll call that computer that hosts VC++ "host" for now on). To do this, create a folder in the remote computer and share it so that the host computer can see it. You must do the same thing in the host computer. Create a folder called "Test" and share it so that the remote computer can access it.

The next step is to copy the remote debugger files to the remote machine. To do this, in the host computer, map the drive that you shared early in the remote computer. After mapping the drive, copy the remote debugger files. These files can be found in the Visual Studio Folder at the subfolder Common\MsDev98\Bin. These files are:

DM.DLL
MSDIS110.DLL
MSVCMON.EXE
MSVCP60.DLL
PSAPI.DLL
TLN0T.DLL

When the files are copied, in the remote computer, go to the folder where the files were copied. Find the MSVCMON.EXE file and start it. When you start it, you'll see the following screen:

When you see this screen, hit the Connect button, so that your machine starts to listen for any connection to the remote debugger. The following screen will be shown.

Setting Up the VC++ Project

We have the remote computer up and running. Now we are going to use the sample project to test the remote debugger. First, copy the sample project files to the shared "Test" folder in the host computer. Open the sample project and locate the OnPaint message handler function. The function must contain this code:

C++
CPaintDC dc(this); // device context for painting

if (IsIconic())
{

	SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

	// Center icon in client rectangle
	int cxIcon = GetSystemMetrics(SM_CXICON);
	int cyIcon = GetSystemMetrics(SM_CYICON);
	CRect rect;
	GetClientRect(&rect);
	int x = (rect.Width() - cxIcon + 1) / 2;
	int y = (rect.Height() - cyIcon + 1) / 2;

	// Draw the icon
	dc.DrawIcon(x, y, m_hIcon);
}
else
{
	CDialog::OnPaint();
	for(int i=0;i<640;i+=50)
	{
		dc.TextOut(200,i, "THIS IS DRAWED STEP BY STEP!");
	}
}

Set a break point at the line containing the "for" statement, so that we can step into the code while the window is being drawn.

The next step is to set the project to run using the remote debugger. Go to the Project Menu and select the Settings menu item. The project settings window should appear. Select the Debug Tab. In this window, we will see 4 text boxes. In the first check box, you need to type the complete path of the application executable file as the host computer sees it. (Example: My project is running under C:\Test in the host computer, so you need to type C:\Test\TestRemoteDebug.exe).

The second and third text box can be just blank. In the fourth text box, you need to type the path of the application as the remote computer sees it. If you have copied the sample project to the "Test" folder, you need to inform the path of the mapped drive in the remote computer (Example: Let's say that you have mapped out "Test" folder of the host computer in the F: drive letter of the remote computer. In this case, you need to inform F:\TestRemoteDebug.exe in the text box). After this step, you can close the project settings window.

We are almost ready! Now you need to inform to the project which computer will be the remote debugger. To do this, go to the Build Menu and select the "Debugger Remote Connection..." option. Within this window, select the TCP/IP protocol and click on settings. In the settings window, inform the name or IP address of the remote computer. After that, you can close this window hitting the ok button.

Ok! We are ready! Start your project by hitting the F5 key (or Run menu item). The first time you execute, you'll probably see a screen like this:

This happens because VC++ needs to find a local reference of each DLL that the project uses in the local machine. The first time this message box appears, just inform the correct path of the local DLLs.

Now just step into the code in the host computer and see what happens in the remote machine! Have fun!

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Web Developer
Brazil Brazil
Mauricio Ritter lives in Brazil, in the city of Porto Alegre. He is working with software development for about 8 years, and most of his work was done at a bank, within a home and office banking system.
Mauricio also holds MCSD, MCSE, MCDBA, MCAD and MCT Microsoft certifications and work as a trainer/consultant in some MS CTEC in his city.
Mauricio also works in his own programming site, aimed to Brazilian Developers: http://www.dotnetmaniacs.com.br

In his spare time he studys korean language...

Comments and Discussions

 
QuestionRemote system not found. Pin
Member 1500266725-Nov-20 2:19
Member 1500266725-Nov-20 2:19 
GeneralMy vote of 5 Pin
Gianluca.Piga7-Aug-13 1:03
Gianluca.Piga7-Aug-13 1:03 
QuestionWhat DLLs do you use? Pin
pHRO gHO16-Dec-09 5:05
pHRO gHO16-Dec-09 5:05 
QuestionHow to remote debugging a program running on a PC with a private IP address? Pin
ehaerim18-Sep-08 10:41
ehaerim18-Sep-08 10:41 
GeneralDifferent OS Pin
MasthanRao15-May-07 7:38
MasthanRao15-May-07 7:38 
GeneralNeed Urgent Pin
UrukundappaGudise7-Nov-06 23:57
UrukundappaGudise7-Nov-06 23:57 
GeneralRemote Debugging Pin
Programmer Anju15-Jun-06 22:44
Programmer Anju15-Jun-06 22:44 
GeneralRemote debugging Pin
Raj241115-May-06 20:49
Raj241115-May-06 20:49 
General.remote Pin
Toby Opferman9-May-04 8:10
Toby Opferman9-May-04 8:10 
Generalsimplified Terminal Server Pin
andré_k6-Dec-03 1:02
andré_k6-Dec-03 1:02 
GeneralRe: simplified Terminal Server Pin
Member 78697725-Dec-03 23:47
Member 78697725-Dec-03 23:47 
GeneralAttaching the debugger to a remote running process Pin
cvind24-Feb-03 23:29
cvind24-Feb-03 23:29 
GeneralRe: Attaching the debugger to a remote running process Pin
Rudresh4-Feb-05 0:19
Rudresh4-Feb-05 0:19 
GeneralRe: Attaching the debugger to a remote running process Pin
Raj241115-May-06 2:19
Raj241115-May-06 2:19 
GeneralIt's all much easier with dual monitor video cards Pin
Rouslan Grabar [Russ]19-Dec-02 5:04
Rouslan Grabar [Russ]19-Dec-02 5:04 
GeneralRe: It's all much easier with dual monitor video cards Pin
SLy209723-Nov-03 6:03
SLy209723-Nov-03 6:03 
GeneralRe: It's all much easier with dual monitor video cards Pin
Max Santos20-Apr-04 10:53
Max Santos20-Apr-04 10:53 
Generalofftopic - Null modem Pin
Amit Dey8-Nov-02 5:12
Amit Dey8-Nov-02 5:12 
GeneralRe: offtopic - Null modem Pin
Mauricio Ritter10-Nov-02 0:52
Mauricio Ritter10-Nov-02 0:52 
GeneralPROBLEM WITH ABOVE STEPS Pin
nthareja10-Aug-02 4:22
nthareja10-Aug-02 4:22 
Generalthanks.. Pin
Bernhard28-May-02 20:43
Bernhard28-May-02 20:43 
GeneralRe: thanks.. Pin
Mauricio Ritter29-May-02 5:56
Mauricio Ritter29-May-02 5:56 
GeneralCannot find the application on the remote machine Pin
Angus Comber14-Mar-02 3:22
Angus Comber14-Mar-02 3:22 
GeneralRe: Cannot find the application on the remote machine Pin
Mauricio Ritter14-Mar-02 4:41
Mauricio Ritter14-Mar-02 4:41 
GeneralRe: Cannot find the application on the remote machine Pin
coder9876519-Jul-10 3:09
coder9876519-Jul-10 3:09 
Hi everybody!
Me and my coworker independently receive the same result :
>>Cannot find the application on the remote machine
So I think Mauricio Ritter missed a point in his description.

Dear Mauricio would you please fix your description.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.