CreateToolWindow2

Does anyone have any code examples (C#) on how to use CreateToolWindow2 method?
[79 byte] By [Werdna] at [2008-2-15]
# 1
Here is a C# sample of CreateToolWindow2. I created my toolwindow in a C# add-in. You could paste the code in the OnConnection method for a C# add-in for VS. Hope you find it helpful.

EnvDTE80.DTE2 dte2obj;

EnvDTE80.Windows2 wins2obj;

AddIn addinobj;

object ctlobj=null;

Window newwinobj;

_applicationObject = (DTE2)application; //application is a parameter passed in to the OnConnection method

_addInInstance = (AddIn)addInInst; //addInInst is a parameter passed in to the OnConnection method

dte2obj= _applicationObject;

//a toolwindow needs to be connected to an add-in. In this sample code, I've just used one of the add-ins created

addinobj = dte2obj.AddIns.Item(1);

wins2obj = (Windows2)dte2obj.Windows;

//Create a windows control that you would want to host inside the tool window, provide the path, class name, a unique guid, caption for the toolwindow

//for the control

string assemblypath = "d:\\temp\\CreateHelloWorldToolWindow.dll";

string classname = "CreateHelloWorldToolWindow.UserControl1";

string guidpos = "{426E8D27-3D33-4fc8-B3E9-9883AADC679F}";

string caption = "CreateToolWindow2 Test";

newwinobj = wins2obj.CreateToolWindow2(addinobj, assemblypath, classname, caption, guidpos, ref ctlobj);

newwinobj.Visible = true;

Kalpana at 2007-8-21 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 2

thanks, that worked.

Now, i'm getting a weird error when debuggin the project, and I open tool window thru Tools menu (with some basic user control in it), when I close VS, I get:

System.Runtime.InteropServices.ExternalException was unhandled
Message="External exception"
Source="System.Windows.Forms"
ErrorCode=-2147467263
StackTrace:
at System.Windows.Forms.Control.ActiveXImpl.ThrowHr(Int32 hr)

at System.Windows.Forms.Control.ActiveXImpl.DoVerb(Int32 iVerb, IntPtr lpmsg, IOleClientSite pActiveSite, Int32 lindex, IntPtr hwndParent, COMRECT lprcPosRect)

at System.Windows.Forms.Control.System.Windows.Forms.UnsafeNativeMethods.IOleObject.DoVerb(Int32 iVerb, IntPtr lpmsg, IOleClientSite pActiveSite, Int32 lindex, IntPtr hwndParent, COMRECT lprcPosRect)

It doesn't matter if I still have the tool window open, or closed, it always throws this error. When I do not open the tool window, and close VS, there is no error.

Werdna at 2007-8-21 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 3
I'm suffering from this exception too. Have you, Werdna, or someone else found a solution since?

Regards,
Thomas

ThomasFreudenberg at 2007-8-21 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 4
BTW, ErrorCode = -2147467263 = 0x80004001 = "Not implemented"
ThomasFreudenberg at 2007-8-21 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified