Microsoft KB Archive/822328

= How to debug a Microsoft Foundation Class (MFC) Automation Server application from a Visual Basic client application in Visual C++ 6.0 =

Article ID: 822328

Article Last Modified on 5/23/2007

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition

-





IN THIS TASK
 * Summary
 * More Information
 * Create an MFC Automation Server Application
 * Create a Client Application
 * Debug the MFC Automation Server Application
 * Method 1
 * Method 2
 * References



SUMMARY
This step-by-step article describes how to debug a Microsoft Foundation Class (MFC) Automation Server application by using a Microsoft Visual Basic client application.

back to the top



Create an MFC Automation Server Application
 Start Microsoft Visual C++ 6.0. On the File menu, click New, and then click MFC AppWizard (exe). In the Project Name box, type DemoServer, and then click OK. Click Next until you reach page 3 of the MFC AppWizard. On page 3, click to select the Automation and the ActiveX Controls check boxes. Click Finish, and then click OK.</li> On the View menu, click ClassWizard, and then click the Automation tab.</li> In the Class name list, click CServerDemoDoc, and then click Add Method.</li> In the External name box, type AddNumber .</li> In the Return Type list, click long.</li> In the first row of the Name text box, type Num1, and then click long in the Type list.</li> In the second row of the Name text box, type Num2, and then click long in the Type list.</li> Click OK to close the Add Method dialog box.</li> Click Edit Code in the MFC ClassWizard to edit the method that you added.</li>  Modify the function as follows: long CDemoServerDoc::AddNumber(long Num1, long Num2) {

return Num1 + Num2; } </li> Build, and then run the application to register it on your system. Close the application.</li></ol>

back to the top

Create a Client Application
<ol> Start Microsoft Visual Basic 6.0.</li> On the File menu, click New Project.</li> Click Standard EXE, and then click OK. By default, Form1 is created.</li> Double-click the CommandButton icon in the toolbox to add Command1 to Form1.</li> Double-click Command1.</li>  Modify the Command1_Click subroutine as follows: Dim myobj As Object Dim sum As Long

Set myobj = CreateObject(&quot;DemoServer.Document&quot;) sum = myobj.AddNumber(10, 20) MsgBox sum </li></ol>

back to the top

Debug the MFC Automation Server Application
You can debug the MFC Automation Server application by using one of the following methods:

Method 1

 * 1) Start Microsoft Visual C++ 6.0, and then open the DemoServer solution.
 * 2) On the Project menu, click Settings, and then click the Debug tab.
 * 3) In the Program arguments box, type /Embedding . This is a command-line argument. Click OK.
 * 4) Press F5 to start debugging.
 * 5) Press F9 to set a breakpoint on the line that contains the return statement in the AddNumber function.
 * 6) Start Microsoft Visual Basic 6.0, and then open the client application.
 * 7) Press F9 to set breakpoint on the AddNumber method, and then press F5 to start debugging.
 * 8) Click Command1 on the Form1 application.
 * 9) Control stops on the AddNumber method. Press F8 to step into the method.

The Visual Basic client application breaks into Visual C++ code.

back to the top

Method 2

 * 1) Start Microsoft Visual Basic 6.0, and then open the client application.
 * 2) Press F9 to set a breakpoint on the AddNumber method, and then press F5 to start debugging.
 * 3) Click Command1 on the Form1 application. The CreateObject method starts Automation Server (DemoServer.exe).
 * 4) Start Microsoft Visual C++ 6.0.
 * 5) On the Build menu, point to Start Debug, and then click Attach to Process.
 * 6) Under Process, click DemoServer, and then click OK.
 * 7) On the File menu, click Open, and then locate the DemoServerDoc.cpp file. This file is located in the \DemoServer directory.
 * 8) Press F9 to set a breakpoint on the line that contains the return statement in the AddNumber function.
 * 9) Switch to the client application, and then press F8 to step into the method.

The Visual Basic client application breaks into Visual C++ code.

back to the top

<div class="references_section">