Hello,
I'm writing C# code and executing it using InstallUtilLib.dll from custom
action during an installation process. It works fine.
I've written some code to add an item (component) to Visual Studio .NET 2003
toolbox and I've got some serious problems with it.
Problem looks like this:
1) My code works if Visual Studio is already opened when my code executes.
2) My code works fine when executed outside of an installation project.
3) If my code is executed from an installation project and Visual Studio is
not opened, then ToolBox item is not added. I've added a "MessageBox" during
the process and I can confirm that devenv.exe *is* executed.
Here is a function used to get access to Visual Studio's process:
bool OpenVisualStudioHandle(out EnvDTE.DTE dteObject)
{
// sprobuj uzyskac dostep do wczesniej otwartego okna Visual Studio .NET 2003
try
{
dteObject = (EnvDTE.DTE)
System.Runtime.InteropServices.Marshal.GetActiveOb ject("VisualStudio.DTE.7.1");
}
catch
{
dteObject = null;
}
if (dteObject != null) return false;
// nie ma otwartego okna z Visual Studiem - otworz nowe
dteObject = (EnvDTE.DTE)
Microsoft.VisualBasic.Interaction.CreateObject("Vi sualStudio.DTE.7.1", "");
return true;
}
And here is the code:
void CreateComponentInVisualStudioToolBox()
{
EnvDTE.DTE dteObject;
bool dteObjectCreated = OpenVisualStudioHandle(out dteObject);
if (dteObject == null) return;
try
{
EnvDTE.Window ToolBoxWnd =
dteObject.Windows.Item(EnvDTE.Constants.vsWindowKi ndToolbox);
EnvDTE.ToolBoxTab tlbTab = GetToolBoxTabByName(ToolBoxWnd, "Components");
if (tlbTab != null)
{
// pokaz okno ToolBox (mozna dokonywac zmian tylko, jesli okno jest
widoczne)
ToolBoxWnd.Visible = true;
// wybierz zakladke "Components"
tlbTab.Activate();
EnvDTE.ToolBoxItems tlbItems = tlbTab.ToolBoxItems;
// dopisz siebie do toolboxa
string DllFullPath =
System.Reflection.Assembly.GetExecutingAssembly(). Location;
tlbItems.Add("CodeCityReaderPort", DllFullPath,
EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatDotN ETComponent);
}
}
finally
{
// zamknij Visual Studio, jesli na poczatku je otworzyles
if (dteObjectCreated)
{
dteObject.Quit();
}
}
}
--
SÅ‚awomir Piotrowski / Telsat GP
Rejestracja Czasu Pracy i Kontrola Dostępu
http://www.ewidencja-czasu-pracy.pl