Debugging .NET code and VB6 code

I am hosting a .NET UserControl inside a VB6 MDI(as per article http://blogs.msdn.com/vbteam/archive/2006/11/02/interop-roadmap-usercontrols-mdi-and-data.aspx)

Could anyone suggest a good debugging strategy to trace code running in the .NET control while being hosted in the VB6 app




Answer this question

Debugging .NET code and VB6 code

  • Chris Jiang

    It works finally. Thank you for your help.
  • iansbrainstorm

    If you double-click My Project in Solution Explorer and go to the Debug tab you'll see an option that says "Start External Program." Select this option and type in "C:\Program Files\Microsoft Visual Studio\vb6.exe." (with quotes).

    After that, put the full path to your .vbp file in the command line arguments (also with quotes around it). Now when you run VS will fire up VB6, and the debugger's attached. You can then set and hit breakpoints in the normal way you're used to.

    Alternately you can also do this using Tools->Attach to process, but personally I find the first approach easier. You set it up once and then you don't have to worry about it again.

    One thing to watch for is if you hit Stop in VS2005, your VB6 program will exit without prompting you to save, so if you make any changes in your VB6 project make sure you click Save before pressing F5 (in VB6).

    Hope that helps, please let us know if you have any issues with this.

    Thanks,

    Jonathan



  • Aaron Leiby

    Hi Eric,

    I just tried it out and it worked fine on my machine; are you sure you referenced both TLBs When you add the control to your VB6 Toolbox it'll automatically add a reference to <NameofYourLibrary>Ctl, but you also need to add a reference to <NameofYourLibrary>.

    The reason is the events fire through the first TLB, not the Ctl one that VB6 creates. Other than that though your code looks fine.

    Hope that helps,

    Jonathan



  • Kanhaiya

    I am hosting a .NET UserControl inside a VB6 MDI too. But I am facing a big problem.

    I define a custom event on it, but can't fire the event in VB6

    Here is my code in VB.net

    Public Event OpenFormEvent As OpenFormEventHandler
    Public Delegate Sub OpenFormEventHandler(ByVal Rpt_Frm As String)
    Private Sub CmdPrint_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdPrint.Click
    RaiseEvent OpenFormEvent("frmMain")
    End Sub

    Here is my code in VB6

    Dim WithEvents UserControl1Events As InteropUserControl.UserControl
    Private Sub Form_Load()
    Set UserControl1Events = Me.UserControl1
    End Sub
    Private Sub UserControl1Events_OpenFormEvent(ByVal Rpt_Frm As String)
    MsgBox("click")
    End Sub

    Anything wrong in my code Anybody can help me Thank you!!!


  • Debugging .NET code and VB6 code