Breakpoint in OCX

BoncekJohn-9525 156 Reputation points
2021-07-27T14:16:06.693+00:00

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?

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
938 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 47,966 Reputation points
    2021-07-27T14:34:06.29+00:00

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful