One thing that always bothered me is the workflow when debugging media center plugins.

I’m used to pressing F5 and having my debugger automatically attach to my process. This is not the way it works for media center plugins.

To launch a media center plugin you have to execute ehshell.exe, and to debug these plugins you need to attach to exexthost.exe, a different process.

So, for example, our debug option for media browser says:

  • Start external program: C:\Windows\ehome\ehshell.exe

  • Command line arguments: /entrypoint:{CE32C570-4BEC-4aeb-AD1D-CF47B91DE0B2}{FC9ABCCC-36CB-47ac-8BAB-03E8EF5F6F22}

This configuration forces media center to launch our media browser plugin on start-up.

But… it only attaches to ehshell.exe forcing us a second, very annoying step which involves hunting down ehexthost.exe in the process list and attaching to it. It’s such a waste of time.

So … I wrote a little visual studio macro to take care of this shoddy work flow:

Public Sub CompileRunAndAttachToEhExtHost()

    DTE.Solution.SolutionBuild.Build(True)
    DTE.Solution.SolutionBuild.Debug()

    Dim trd As System.Threading.Thread = _
        New System.Threading.Thread(AddressOf AttachToEhExtHost)
    trd.Start()

End Sub

Public Sub AttachToEhExtHost()
    Dim i As Integer = 0
    Do Until i = 50
        i = i + 1
        Try

            For Each proc In DTE.Debugger.LocalProcesses
                If (proc.Name.IndexOf("ehexthost.exe") <> -1) Then
                    proc.Attach()
                    Exit Sub
                End If
            Next
        Catch e As Exception
            ' dont care - stuff may be busy 
        End Try
        Threading.Thread.Sleep(100)
    Loop
End Sub

To install it:

  • Tools->Macros->Macros IDE…

  • Expand MyMacros

  • Paste the code into yor macro file

Next, bind your macro to a shortcut key

  • Tools->Options->Keyboard

  • Click on “Press shotcut keys:”

  • Press the shortcut you want (I use CTRL-SHIFT-ALT-A)

  • Start a search in the "show commands containing… " box. Search for “CompileRunAndAttachToEhExtHost”

  • Click Assign

Your done …

Now to Compile->Launch and Debug your media center plugin all you need to do is click CTRL-SHIFT-ALT-A

Comments

Charlie_Owen almost 16 years ago
Charlie_Owen

What happens if there are multiple instances of ehExtHost.exe running?

Sam Saffron almost 16 years ago
Sam Saffron

@Charlie

It's possible to have multiple processes of ehexthost.exe running if you have any plugins that are set to automatically start with media center. For example, I think media control is set to run in the background. (I know you know this, just want to make sure its clear to others)

In those situations the macro will attach to the first instance of ehexthost.exe and then exit, so you may not get the desired effect.

If you remove the “Exit Sub” line from the macro it will attach to all plugins.

It is also possible to write a function that inspects the loaded dlls in ehexthost and then only attaches to ones that have the plugin dll loaded.

Cheers
Sam

Gabriel over 13 years ago
Gabriel

“■Start a search in the "show commands containing… " box. Search for “CompileRunAndAttachToEhExtHost”
"

This does not bring up the macro module. What should I do? I use VS2010.


comments powered by Discourse