HOWTO: Debug an Out-of-Process Server with VC++

ID: Q200034


The information in this article applies to:
  • Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0


SUMMARY

Microsoft Knowledge Base article Q166275 "HOWTO: Debug a Native Code Visual Basic Component in VC++" demonstrates debugging Visual Basic in-process servers (DLLs and OCXs) as well as standard executables using the VC++ debugger. However, to debug an out-of-process server, you need to set things up differently. This article demonstrates how to debug an ActiveX out-of-process server component using the Visual C++ debugger.


MORE INFORMATION

Creating the Demo Server

  1. Start Visual Basic and create a new ActiveX EXE project, then rename the project to DemoSvr.


  2. Add the following code to the default class (Class1):
    
          Dim strProp As String
          Public Property Let StringProp(s As String)
              strProp = s
          End Property
          Public Property Get StringProp() As String
             StringProp = strProp
          End Property 


  3. From the Project menu, select DemoSvr Properties and switch to the Compile tab.


  4. Make sure that Compile to Native Code, Create Symbolic Debug Info, and No Optimization are selected.


  5. Save and compile the project to create DemoSvr.exe.


Creating the Demo Client

  1. Start Visual Basic and create a Standard EXE project, then rename the project to DemoCli.


  2. From the Project menu, select References.


  3. Find and check DemoSvr and make sure it's pointing to the DemoSvr.exe you just built. Click OK.


  4. Add a CommandButton to the default form (Form1).


  5. Add the following code to the module of Form1:
    
          Private Sub Command1_Click()
              Dim objServer As New DemoSvr.Class1
              objServer.StringProp = "Test"
              Command1.Caption = objServer.StringProp
              Set objServer = Nothing
          End Sub 

    If you want to debug the client also, set the compile options for DemoCli to be the same as those of the DemoSvr. To do this, select DemoCli Properties from Project menu and switch to the Compile tab. Make sure Compile to Native Code, Create Symbolic Debug Info, and No Optimization are selected.


  6. Save and compile the project to create DemoCli.exe.


Debugging Setup

  1. Start Visual C++ (msdev.exe).


  2. Open DemoSvr.exe as a workspace or a file (Open as Auto).


  3. Open the file Class1.cls and place breakpoints on the lines pointed to by arrows shown below (place the cursor on the line and press the F9 key):



  4. 
          Public Property Let StringProp(s As String)
    ==>     strProp = s
          End Property
          Public Property Get StringProp() As String
    ==>      StringProp = strProp
          End Property 

  5. From the Project menu, select Settings.


  6. On the Debug tab under Program arguments, type "/embedding" without the quotes.


  7. Press the F5 key to start the server. At this point, DemoSvr.exe would be loaded and waiting for any potential client connections.


  8. Start the DemoCli.exe and click Command1 to start debugging. You will hit the "strProp = s" breakpoint.


Alternatively, you can start the server first then attach the debugger to it as shown below:
  1. Start DemoSvr.exe from the command line by typing "demosvr /embedding" without the quotes.

    Once this command is run, you can see that DemoSvr.exe is loaded in the Task Manager even without any client process running.


  2. Start Visual C++ (msdev.exe).


  3. Open Class1.cls and place your breakpoints as before.


  4. From the Build menu, select Start Debug, and then choose Attach to Process.


  5. Select DemoSvr from the process list.


  6. Run DemoCli.exe as shown above.


If you want to debug the client as well, you need to start another instance of Visual C++ (msdev.exe) as shown below:
  1. Start Visual C++ and load the server and class module as shown above. Place your breakpoints.


  2. Start a new instance of Visual C++ (msdev.exe).


  3. Open DemoCli.exe as a workspace.


  4. Open Form1.frm and place breakpoints at desired locations.


  5. Press the F5 key to start the client. Use the F10 key to step over a line and the F11 key to step into a call.


Command Line Arguments for Local Servers:

There are three command line options for launching a out-of-process server:
  • /regserver - tells the server to register itself and its associated type library.


  • /unregserver - tells the server to unregister itself and its associated type library entries.

  • /embedding - keeps the out-of-process server in memory waiting for the first client to connect. In fact, COM services passes this argument to a out-of-process server when it attempts to launch it.


REFERENCES

For additional information about debugging Visual Basic ActiveX components in VC++, please see the following article in the Microsoft Knowledge Base:

Q166275 HOWTO: Debug a Native Code Visual Basic Component in VC++

You may also want to look at Chapter 5 in "Inside OLE" by Kraig Brokschmidt, from Microsoft Press.

Additional query words: debug; debugging; "local server"

Keywords : kbsample kbActiveX kbVBp kbVBp500 kbVBp600 kbVC500 kbVC600 kbGrpVB
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: March 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.