The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Writing a VS.Net Add-in, ugh

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Roy Osherove

Posts: 1807
Nickname: royo
Registered: Sep, 2003

Roy Osherove is a .Net consultant based in Israel
Writing a VS.Net Add-in, ugh Posted: Jun 12, 2004 10:33 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: Writing a VS.Net Add-in, ugh
Feed Title: ISerializable
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/rosherove/Rss.aspx
Feed Description: Roy Osherove's persistent thoughts
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Roy Osherove
Latest Posts From ISerializable

Advertisement
I've been dabbling a bit with the notion of creating a Regulator Add-in for VS.Net. Still not sure what exactly it will feature  - got any suggestions?
Anyway - I don't have much experience with writing Add-ins for vs.net so I happily started one project. Boy - it should not be this hard. Even trying to do something as simple as creating a tool window in Vs.Net is really hard.
All the interfaces and extensibility model of VS is still in set in the wayback machine  - meaning COM interfaces and ActiveX galore.
I wonder - when will COM be like COBOL? (And will we call it “COMOL“?)
 
Anyway - to make a short story long and unreadable, the only way to make a tool window in VS.Net that features your .Net control is to make it host an ActiveX host control. That means you need to make an ActiveX control that will host your own .Net managed user control which will reside inside it. it's pretty horrific.
 
A nice intro article to this whole ToolWindow horror can be read here.
The question remains - how do you get an ActiveX control that will host your .Net user control inside it?
Luckily for us developers - this dark corner of the universe has been exposed: there is a ATL C++ implementation of just such an ActiveX control. You can get it here , look for “ToolWindow Add-ins“ down in the page (and here's a direct download link).
once you get past this hurdle - you can actually write wonderful(ugly, long) code.
 
So, the least I could do is refactor that bit of code you need to write into some form of generic Class with a static method.
 
---------------------
Here's the code for a simple VB.Net class that takes some of the pain out of this process:
 

Public Class ControlHoster

    Public Shared Function SetupToolWindow(ByVal applicationObject As EnvDTE.DTE, _

                                            ByVal addInInstance As EnvDTE.AddIn, _

                                            ByVal caption As String, _

                                            ByVal HostedControlFullName As String)

 

        Dim GUIDString As String = Guid.NewGuid().ToString()

        Dim ProgID As String = "VSUserControlHost.VSUserControlHostCtl"

        Dim assemblyLocation As String = System.Reflection.Assembly.GetExecutingAssembly().Location

        Dim objTemp As Object = Nothing

 

        Dim retVal As EnvDTE.Window = _

                applicationObject.Windows.CreateToolWindow(addInInstance, _

                                                            ProgID, _

                                                            caption, _

                                                            GUIDString, _

                                                            objTemp)

 

 

 

        retVal.Visible = True

        objTemp.HostUserControl(assemblyLocation, HostedControlFullName)

 

        Return retVal

    End Function

 

End Class       

 
 
I really like doing this in VB.Net - makes all the casting and Reflection goo work seamlessly.
Anyway - I'm still not happy about this. I'm now facing  a more difficult problem - my Add-in does not even show up in the “Tool“ menu. I bet it's something really silly, isn't it?

Read: Writing a VS.Net Add-in, ugh

Topic: Moving from a green screen is hard Previous Topic   Next Topic Topic: .NET and Mono: The Libraries, the Framework and the Very Big Fish

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use