How to debug VB6 OCX under VB6
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: How to debug VB6 OCX under VB6

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    3

    How to debug VB6 OCX under VB6

    I know this has been asked before, but....

    Using the VB6 IDE, how can I debug (ie, set breakpoints, etc) a VB6 OCX that's invoked by a VB6 exe?

    I have the source for both the exe and the OCX. I would like to be able to debug by putting the EXE and OCX projects in the same "group".

    But I've tried every "how to" tip I've found, and I can't get it to work. I set a breakpoint in the OCX project, and it's never hit. I suspect it's using the registered OCX, not the code in my OCX project. One of the posts I read mentioned to not point to the wrong OCX, but didn't explain how to do that, and I'm a little unclear about how to "direct" VB6 to "use the OCX project" during debug.

    What's the complete list of steps necessary to get this to work?

    Thanks in advance!

    DadCat

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,945

    Re: How to debug VB6 OCX under VB6

    Put both source files in the same project, and then you can debug one from within the other
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2011
    Posts
    3

    Re: How to debug VB6 OCX under VB6

    This is a legacy app that I'm rewriting in C# so my objective is to first thoroughly understand what it's doing (the original author has long since left).

    I'm afraid combining the source of the EXE and OCX might subtlely alter the behaviour. So I need to be able to debug the two as separate projects without combining the source.

    There are posts in this forum which describe the general process of debugging while keeping the EXE and OCX in separate projects (create a project group, set the EXE as the startup project, etc), but I can't make it work.

    As I noted, it's acting as if the EXE (running under VB6 IDE) is invoking the registered OCX, and not the OCX project in the project group under the IDE.

    DadCat

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,945

    Re: How to debug VB6 OCX under VB6

    If it loads the OCX, it's compiled
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Apr 2011
    Posts
    3

    Re: How to debug VB6 OCX under VB6

    I got it to work! Here's the cause of the problem I was seeing...

    I began with an existing ActiveX Control (OCX) project. That control was referenced on a form within an existing Standard EXE project. I opened both projects in a group, and set the EXE as the Start Up. But no matter what I did, I couldn't get it to breakpoint in the control's code.

    I eventually realized the problem was that the reference in the EXE to the control was to a previously-registered OCX - NOT to the OCX being built on-the-fly by the VB6 IDE (from the OCX project in the project group).

    Thus the key missing step was to first delete the control from the form (in the EXE), comment-out the code in the EXE that referenced the control (fortunately, not much) and then remove the Component reference to the OCX from the EXE project. Once I had the EXE building cleanly without any references/usage of the control, I could then add the OCX project to the EXE project (creating a project group), then add the control back on the form (but this time referencing the OCX project), un-comment-out the code.

    And then it worked!

    Here's the step-by-step:

    1) Open EXE project and remove the ActiveX control from the form and comment-out the code that references the control. Save/close/reopen the EXE project and then remove the reference to the control (Project -> Components). Build the EXE to make sure it no longer used the control.

    2) Add the OCX project to the EXE project (File -> Add Project - Existing tab), creating a Project Group. Set the EXE project as Start Up. Do File -> Make Project Group just to see if everything builds.

    3) Make sure the control isn't open in the designer, then click the control's icon in the ToolBox and draw it onto the EXE's form. Un-comment the lines in the EXE source code you commented-out earlier.

    4) Set breakpoint in the control's code, and hit F5.

    DadCat

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,945

    Re: How to debug VB6 OCX under VB6

    Great! Glad you contributed to the forum, with the results!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center