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



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual C++ Standard Edition, version 6.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition

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

MORE INFORMATION

Create an MFC Automation Server Application

  1. Start Microsoft Visual C++ 6.0.
  2. On the File menu, click New, and then click MFC AppWizard (exe).
  3. In the Project Name box, type DemoServer, and then click OK.
  4. Click Next until you reach page 3 of the MFC AppWizard.
  5. On page 3, click to select the Automation and the ActiveX Controls check boxes.
  6. Click Finish, and then click OK.
  7. On the View menu, click ClassWizard, and then click the Automation tab.
  8. In the Class name list, click CServerDemoDoc, and then click Add Method.
  9. In the External name box, type AddNumber.
  10. In the Return Type list, click long.
  11. In the first row of the Name text box, type Num1, and then click long in the Type list.
  12. In the second row of the Name text box, type Num2, and then click long in the Type list.
  13. Click OK to close the Add Method dialog box.
  14. Click Edit Code in the MFC ClassWizard to edit the method that you added.
  15. Modify the function as follows:
    long CDemoServerDoc::AddNumber(long Num1, long Num2) 
    {
    
    	return Num1 + Num2;
    }
  16. Build, and then run the application to register it on your system. Close the application.
back to the top

Create a Client Application

  1. Start Microsoft Visual Basic 6.0.
  2. On the File menu, click New Project.
  3. Click Standard EXE, and then click OK. By default, Form1 is created.
  4. Double-click the CommandButton icon in the toolbox to add Command1 to Form1.
  5. Double-click Command1.
  6. Modify the Command1_Click subroutine as follows:
    Dim myobj As Object
    Dim sum As Long
    
    Set myobj = CreateObject("DemoServer.Document")
    sum = myobj.AddNumber(10, 20)
    MsgBox sum
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

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

151074 How To Debug OLE Server Applications Using MSVC

For more information about automation servers and about MFC debugging support, visit the following Microsoft Developer Network (MSDN) Web sites:back to the top

Modification Type:MinorLast Reviewed:8/19/2005
Keywords:kbinfo kbHOWTOmaster kbDebug kbComCtrls kbhowto KB822328 kbAudDeveloper