Click here to Skip to main content
Click here to Skip to main content

Common Issues & Solutions While Creating Custom ToolBar For IE

, 8 Oct 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Solutions For Common Problems While Using Band objects

Introduction

There are a lot of extensions for the wonderful Band Objects

http://www.codeproject.com/csharp/dotnetbandobjects.asp

that Pavel Zolnikov has provided. I have been seeing a lot of queries regarding the implementations and deployment of the toolbars implementing the band objects.Here I will try to describe some common problems that many of us have experienced while working with the band object.

Problem #1 : Creating Strong Names For ActiveX Assemblies

The first problem that I will address here is with regards to the strong names of assemblies.
The strong naming of the BandObjectLib and the Implementing assembly very well in the above mentioned article itself.
The challenge is when the assemblies are copied into the GAC an error that occurs could be

Error 2 Assembly generation failed -- Referenced assembly 'Interop.SHDocVw' does not have a strong name .

This can happen due to the fact that the IE Engine component dosent have a strong name.
This can be resolved by adding the strong name to the SHDocVw through the following statement from the .NET command prompt.

sn -k shdocvw.snk 
AxImp %WINDIR%\System32\shdocvw.dll/keyfile:shdocvw.snk


The first statement will generate a key used for signing the dll and the second statement will create the wrapper assemblies with strong names.

The second statement will result in the wrappers for the IE AxSHDocVw.dll and SHDocVw.dll which could be reffered in place of the earlier files

Problem #2 : IE Custom ToolBar Installer

Creating an installer for the band object is what I will deal with next.
I have created a sample project "ToolBar" for implementing the band objects and a setup project "ToolbarInstaller" for installing the ToolBar.
I will explain the different steps involved in this.

1. The first thing that we will do is Add an installer class to the ToolBar project. Right Click the ToolBar project -> Add New Item -> Installer Class

2. The installer class has some events associated with it . Form the designer view go to Properties -> Events ->
and double click on the After Install and the After Uninstall events.

We can use these events to run Regasm utility and Register/Unregister our dlls. The following code could be used to Register the dlls.

private void InstallToolBar_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
{
   try { 
      //Here the Band Object Path will be derived from our 
      //assembly's Location and the name will be replaced 
      
      BandObjectPath = Assembly.GetExecutingAssembly().Location.Remove (
                       Assembly.GetExecutingAssembly().Location.LastIndexOf("//")
                     (Assembly.GetExecutingAssembly().GetName().Name.Length/ + 5));
      BandObjectPath += "//BandObjectLib.dll/"; BandObjectPath = BandObjectPath.Replace(" ",""); 
      ExecAssmPath = Assembly.GetExecutingAssembly().Location.Replace(" ",""); 

      //Start the process "RegAsm" to register the dlls 
      Process.Start (AppPath + "regasm.exe ",BandObjectPath); 
      Process.Start (AppPath + "regasm.exe ", ExecAssmPath); 
  } 
  catch(Exception ex) 
  { 
       EventLog.WriteEntry("Install Exception",ex.Message ); 
  }

Similar code can be used for After UnInstall Function.

3. Now it is time to start the real installation works. First add a new setup project to the solution.Right click on the added setup project go to View -> FileSystem.

Right Click on the opened designer AddSpecialFolder -> Global Assembly Cache Folder

Right click on the GAC folder and Add -> Assembly and add the ToolBar as well as the Band

Object Assembly.This will add these assemblies into GAC during installations.

4. In order that the installer class Events to get triggered,We will have to

link the ToolBar dll to the Installer . For that we will right click on the installer project View -> CustomActions

Again Right Click on the Installation folder on the designer that opens up and click Add Custom Actions and select the application folder ,
browse for the ToolBar.dll and click OK.

This step is to be repeated for the UnInstall folder also.

Problem #3: Packaging .NET FrameWork With Your Application

Till this point we were dealing with installing the applicatio where there is .NET framework installed .What if it is not there .
For that the solution is straight forward.
  1. Download the BootStrapper.exe and install this .
  2. Right Click on the installer Project Go to Properties -> Boot Strapper and select Windows installer BootStrapper.

When your application is getting installed,it will automatically check for the .NET framework and install the same if it is not installed.

Problem #4: Adding ActiveXControls on the ToolBar

Loading an ActiveX controls on the toolbar is another problem that is very commonly faced. The Solution is very straight forward.

  1. Referring to Problem1 , use AxImp utility to add a strong name to the activex dlls
  2. Add these strong named Dlls to the GAC Using the gacutil
  3. Say Your Application is located at C:\MyToolBar

Go to the .NET Command prompt (Start -> ProgramFiles ->VisulaStudio.NET---- ->VisualStudio.NETTools -> Visual Studio .NET Command Prompt) and type

gacutil /if C:\MyToolBar\bin\debug\ActiveX.dll .

If you are using the above installer add the dlls into the GAC using the 3 rd step in Problem #2.

Limitations:

Using the installer that i have created , it is not possible to install the toolbar in C:\Program Files\...
This is Because I couldnt find a straightforward method to get the DOS Path from .NET. There is one method GetShortPathName() in Win32 .
Interested people can read more.
The above mentioned installer will work only on .NET 2003 since the app path is taken

private string AppPath = @"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\"; 

The folder will be something different for other versions.

Conclusion:

The Solutions that I have tried to provide maynot be the best and also not the singular ones. All Suggestions /Comments/Criticisms are whole heartedly welcomed. Please do keep posting about the various problems that you people face while creating the IE toolBars So that I can Keep appending to what is done.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

SandeepSreekumar

United Arab Emirates United Arab Emirates
No Biography provided

Comments and Discussions

 
GeneralVista Pinmembercambler12-Jul-07 15:45 
QuestionIE Toolbar show up automatically after installing toolbar. Pinmemberpeerahmad3-Apr-07 1:37 
Generaltoolbar does not appear on right-click or in view->toolbars after install PinmemberDaryl Sketch20-Dec-06 8:35 
GeneralRe: toolbar does not appear on right-click or in view->toolbars after install PinmembershekharSingh00718-Oct-07 0:49 
GeneralRe: toolbar does not appear on right-click or in view->toolbars after install PinmembershekharSingh00718-Oct-07 21:56 
GeneralRe: toolbar does not appear on right-click or in view->toolbars after install PinmemberNisha Agrawal12-Sep-08 3:54 
GeneralIE7 Issue PinmemberMXX22-Oct-06 16:52 
GeneralRe: IE7 Issue PinmemberMXX23-Oct-06 6:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 8 Oct 2006
Article Copyright 2006 by SandeepSreekumar
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid