Microsoft KB Archive/200034

= How To Debug a Visual Basic Out-of-Process Server with Visual C++ =

Article ID: 200034

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q200034



SUMMARY
Debugging out-of-process servers by using the Microsoft Visual C++ debugger requires a different set up than debugging in-process servers (DLLs and OCXs). This article demonstrates how to debug a Visual Basic ActiveX out-of-process server component by using the Microsoft Visual C++ debugger.

For additional information on how to debug Visual Basic in-process servers, as well as standard executables, by using the Visual C++ debugger, click the article number below to view the article in the Microsoft Knowledge Base:

166275 How To Debug a Native Code Visual Basic Component in VC++



MORE INFORMATION
The first two of the following four sections describe how the Visual Basic ActiveX server application (activex.exe) and the Visual Basic client application (standard.exe) can be built. The third section provides the steps for debugging both the ActiveX server application and the client application through the Visual C++ debugger. The final section provides more information on the command line options for launching an out-of-process server.

Creating the Demo Server
 Start Visual Basic, create a new ActiveX EXE project, and then rename the project to DemoSvr.  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  On the Project menu, select DemoSvr Properties, and then switch to the Compile tab. Make sure that Compile to Native Code, Create Symbolic Debug Info, and No Optimization are selected. Save and compile the project to create DemoSvr.exe.

Creating the Demo Client
 Start Visual Basic, create a Standard EXE project, and then rename the project to DemoCli. On the Project menu, select References.</li> Find and check DemoSvr, and make sure that it is pointing to the DemoSvr.exe file that you just built. Click OK.</li> Add a CommandButton control to the default form (Form1).</li>  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 </li> 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, on the Project menu, select DemoCli Properties, and then switch to the Compile tab. Make sure that Compile to Native Code, Create Symbolic Debug Info, and No Optimization are selected.</li> Save and compile the project to create DemoCli.exe.</li></ol>

Debugging Setup
 Start Visual C++ (msdev.exe).</li> Open DemoSvr.exe as a workspace or a file (Open as Auto).</li>  Open the Class1.cls file and place breakpoints on the lines pointed to by arrows shown as follows. (Place the cursor on the line and press the F9 key.) Public Property Let StringProp(s As String) ==>    strProp = s      End Property Public Property Get StringProp As String ==>     StringProp = strProp End Property </li> On the Project menu, select Settings.</li> On the Debug tab under Program arguments, type /embedding.

NOTE: For more information on the /embedding argument, see the "Command Line Arguments for Local Servers" section.</li> Press the F5 key to start the server. At this point, DemoSvr.exe would be loaded and waiting for any potential client connections.</li> Start the DemoCli.exe and click Command1 to start debugging. Note that you hit the strProp = s breakpoint.</li></ol>

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

Once this command has run, you can see that DemoSvr.exe is loaded in the Task Manager even without any client process running.
 * 1) Start Visual C++ (msdev.exe).
 * 2) Open Class1.cls and place your breakpoints as before.
 * 3) On the Build menu, select Start Debug, and then choose Attach to Process.
 * 4) Select DemoSvr from the process list.
 * 5) Run DemoCli.exe as shown.

If you want to debug the client as well, you need to start another instance of Visual C++ (msdev.exe) as follows:
 * 1) Start Visual C++ and load the server and class module as shown in the preceding step. 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 then 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.

<div class="references_section">