Link to home
Start Free TrialLog in
Avatar of cholden
cholden

asked on

Open Browser Window from Windows App

I have a little application that opens a browser window from a windows application built using VS2005.

Added references for  Microsoft.mshtml  and   interop.shdocvw.

Then created a browser class:

    public class StaticBrowser
    {
        public static IWebBrowser2 TheInstance = new InternetExplorerClass()
                    as IWebBrowser2;
    }


Next used the following code in a menu click to open a browser window:

        private void staticBrowserToolStripMenuItem_Click(object sender,
                            EventArgs e)
        {
            object missing = System.Reflection.Missing.Value;
            StaticBrowser.TheInstance.Navigate("http://www.ezywrap.com",
                    ref missing, ref missing, ref missing, ref missing);
            StaticBrowser.TheInstance.Visible = true;
        }


This is all fine and the browser window opens  -  if I click the menu item again  the same browser window is used and you can see it re-display  -  the same window.

The problem is if the user closes the browser window that was open the following error happens when the user clicks the menu item again to open the browser window.

System.Runtime.InteropServices.COMException (0x80010108): The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

Is there any way to bring up this window again -  I know I can use a non static Browser but that results in a new window with every click which is something I was trying to avoid.

thanks
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cholden
cholden

ASKER

Thank you for the reply  and it points me in a good direction but I am stuck on just how to implement it. I have been unable to find any info elsewhere on this.  

thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cholden

ASKER

What I finally ended up doing was catching the exception and re-initializing the instance -  was trying to avoid doing it this way,  but it works:

            object missing = System.Reflection.Missing.Value;
            try
            {
                StaticBrowser.TheInstance.Navigate("http://www.ezywrap.com", ref missing, ref missing, ref missing, ref missing);
            }
            catch
            {
                StaticBrowser.TheInstance = new InternetExplorerClass() as IWebBrowser2;
                StaticBrowser.TheInstance.Navigate("http://www.ezywrap.com", ref missing, ref missing, ref missing, ref missing);
            }
            StaticBrowser.TheInstance.Visible = true;
        }

thanks