How to debug C++ OCX control in VS2010 hosted by VB6 ActiveX EXE

619 Views Asked by At

I have an OCX control written in C++ and built with VS2010. The host application for the control is a VB6 ActiveX EXE. I am trying to figure out how to debug the OCX control in VS2010. Normally to debug an OCX control you put in the host application that embeds the control into the OCX control's Properties:Debugging:Command field. When I enter the VB6 Host program's EXE and try to start debugging it gives me the following alert boxerror alert

I'm suspecting that the VB6 debug information is not compatible with VS2010. I don't actually need to debug the VB6 ActiveX EXE in this case. (I can do that from VB6 dev enviroment). But I've tried clicking yes to the above dialog and the OCX control runs outside the debugger as it ignores any breakpoints I've set. How do I get the OCX control to run under the debugger?

I've looked at this similar question but it seems a slightly different scenario as it sounds like all the OCX controls this case were in VB6. It talks about setting "Binary Compatibility" for the OCX control but I believe that only applies to VB6 environment and not to C++ under VS2010.

Also is there a way to generate debug info for VB6 ActiveX EXE that is compatible with VS2010 debug environment?

2

There are 2 best solutions below

0
JonN On BEST ANSWER

After some more exploration I found that it is possible to do what I initially asked in my original post.
While the VS2010 debugger doesn't automatically attach to the OCX control when started via the VB6 ActiveX EXE container, it is possible to attach to the OCX control manually. It is in fact possible to be running the container ActiveX EXE in VB6 debugger and simultaneously running the OCX control in VS2010 debugger. Here's the sequence

Start VB6 development environment with the ActiveX EXE project. Start execution of the ActiveX EXE in debug mode. Now start the VS2010 development environment and select menu item Debug:Attach to Process... and then select the VB6 process as the one to attach to. Now breakpoints in the VB6 app will route to the VB6 debugger and breakpoints in the OCX control will route to VS2010 debugger.

If you don't need to debug the VB6 ActiveX EXE you can specify it as the start Command for the VS2010 OCX control and then do the Attach to Process after it starts although using VB6 development environment insures that you can catch breakpoints in the OCX control at startup.

0
JonN On

I have been able to debug OCX control, but the only way I found is to use the TSTCON sample program I gave in the links (TSTCON Still Available and TSTCON Info) in previous comment. I added TSTCON and TCProps as projects to the VS2010 solution with the OCX Control and then specified TSTCON.exe as the debug Command line. Doing this I am able to break point in the OCX control. Starting debug on OCX control will start TstCon. Then when TstCon app starts right click on content area and select "Insert New Control" and select the OCX control from the list of all registered OCX controls. Be sure to select Linker:Register Output:Yes for the OCX Control project. The control will initialize and then any methods can be invoked and parameters specified via the TstCon app menu Control:Invoke Methods...