question

BoncekJohn-9525 avatar image
0 Votes"
BoncekJohn-9525 asked cooldadtx commented

Breakpoint in OCX

In Visual Studio 2013, you can set a breakpoint in code of a .ocx file but the debugger will not stop there. The project is compiled Debug. How do you get a breakpoint to work in this situation?

vs-debugging
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

cooldadtx avatar image
1 Vote"
cooldadtx answered cooldadtx commented

Breakpoints work in OCXs like it does in anything else however it is all about the host and how you're doing it. To debug using a normal approach you would need to start the process that will host the OCX in the debugger (or attach to it). Then you need to load the OCX in the host but the OCX that is loaded needs to be the version that you are building from your project. Since this is COM that means you'd need to ensure the COM registration is pointing to your locally built instance.

In the best situation you should have a simple test host app that you are debugging that loads your OCX. In this case breakpoints just work. However this is often not possible so VS, if I recall correctly, used to ship with an OCX test host that you could use. In the case of a host that you don't have the code to then the breakpoints probably aren't being recognized in the IDE even if they are hit. To work around that set the OCX project as the startup project and set the debugger to run your actual host program instead. Then when the debugger starts you'll be debugging the OCX project but in the context of the external host.

If nothing else works then the final approach is to put a Debug.Assert in your OCX code along a hot path. When this line is executed then it'll prompt to connect to the debugger. Once you're connected then you can set breakpoints and debug normally as you're basically doing the previous scenario.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The code for the ActiveX Control Test Container can be obtained here - TstCon


0 Votes 0 ·

@cooldadtx: Thank you. Setting the OCX as startup and using Debug > Start new instance to run the main project worked to allow breaking in the OCX.

0 Votes 0 ·

No problem.

0 Votes 0 ·