On the discussion part of the SpicIE home page (http://code.msdn.microsoft.com/SpicIE/Thread/List.aspx) I found an interesting question “Constructor is not called…”.

The reason for this scenario is following. If you build IE extensions with SpicIE you finally constructs COM objects which Internet Explorer creates for you.

In your code these classes seems to be normal objects. But from IE perspective this classes are COM objects which are created only once per IE process room. To understand how Internet Explorer 7/8 handles processes and tabs I recommend you this reading about “Loosely-coupled Internet Explorer Internet Explorer” --> http://code.msdn.microsoft.com/ie8whitepapers/Release/ProjectReleases.aspx?ReleaseId=565

So in your own SpicIE code exists two categories of classes:

  • Internet Explorer extension classes
  • Normal .NET classes

The Internet Explorer extension classes have following characteristics:

  • Any Internet Explorer extension class has a ProgID and a GUID
  • Internet Explorer creates the COM object and the corresponding .NET class instance once for you
  • To get access to the object instance you should use the “HostInstance” pattern
  • You can’t control from your code at what time Internet Explorer creates your objects. This means for instance: it could happen that an invisible toolbar has no instance variable until he will be visualized

Here follows a short sample of the HostInstance pattern which could be used to access the Internet Explorer extension class instances.

    public partial class HtmlTreeToolbar : SpicIE.Controls.Toolbar
    {
        public static HtmlTreeToolbar toolbarInstance;

Assignment of the instance in the object constructor:

        public HtmlTreeToolbar()
        {
            try
            {
#if DEBUG
                Host.TraceSink.TraceInformation(string.Format("HtmlTreeToolbar.HtmlTreeToolbar - DEBUG {0} - {1}",
                    System.Reflection.Assembly.GetExecutingAssembly().FullName, DateTime.Now.TimeOfDay.ToString()));
#else
                 Host.TraceSink.TraceInformation(string.Format("HtmlTreeToolbar.HtmlTreeToolbar - RELEASE {0} - {1}",
                    System.Reflection.Assembly.GetExecutingAssembly().FullName, DateTime.Now.TimeOfDay.ToString()));
#endif

                toolbarInstance = this;

Finally usage of the instance variable to access functionality of the Internet Explorer extension class instance:

 

    void PageHtmlTree_OnDocumentComplete(object pDisp, ref object url)
        {
            if (HtmlTreeToolbar.toolbarInstance != null)
            {
                HtmlTreeToolbar.toolbarInstance.StartDisplayNewPageTree( (url!=null) ? url.ToString() : string.Empty );   
            }
        }

GunnarD