By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,030 Members | 2,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,030 IT Pros & Developers. It's quick & easy.

Connecting to a running instance of an embedded webBrowser control

P: n/a
Hi,

ok, I found a way to connect to a running instance of an (external) Internet
Explorer and access - for example - the html source. That works fine!

But now I have running application with an embedded IE webBrowser Control.
Is there a possibility for my application to access the webBrowser control in
the other application, too?

Thanks in advance, Randy

Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Use remoting. In otherwords, expose your Form (which is MarshalByRefObject) over a TCP remoting channel and consume it in any other
..NET application by using client remoting. Make a public property for access to the browser control.

public AxWebBrowser Browser { get { return browserCtrl; } }

public TheForm()
{
System.Runtime.Remoting.Channels.Tcp.TcpChannel channel =
new System.Runtime.Remoting.Channels.Tcp.TcpChannel(10 24);

System.Runtime.Remoting.Channels.ChannelServices.R egisterChannel(channel);

System.Runtime.Remoting.RemotingServices.Connect(t ypeof(TheForm),
"tcp://localhost/theform:1024");
}

To consume the form, your project must have a reference to the assembly which contains TheForm:

public AXWebBrowser GetBrowserFromRemotingForm()
{
System.Runtime.Remoting.Channels.Tcp.TcpChannel channel =
new System.Runtime.Remoting.Channels.Tcp.TcpChannel(0) ;

System.Runtime.Remoting.Channels.ChannelServices.R egisterChannel(channel);

TheForm form = Activator.GetObject(typeof(TheForm), "tcp://localhost/theform:1024");
return form.WebBrowser;
}
I didn't test the code, so it will probably require some mods. Also, realize that when remoting an object such as a Form, all
properties must be serializable in some fashion, whether through declaration or inheritance. In this case it might make more sense
to remote an object to act as a proxy for the Form class that can return the WebBrowser control.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Randy" <Ra***@discussions.microsoft.com> wrote in message news:33**********************************@microsof t.com...
Hi,

ok, I found a way to connect to a running instance of an (external) Internet
Explorer and access - for example - the html source. That works fine!

But now I have running application with an embedded IE webBrowser Control.
Is there a possibility for my application to access the webBrowser control in
the other application, too?

Thanks in advance, Randy

Nov 17 '05 #2

P: n/a
Hi Dave,

thanks for your reply. Unfortunately the program with the embedded
webbrowser control is a "finished" application from another company (and I
don't have a chance to modify the source ;-)).

Is there a possibility to connect to the webbrowser control inside anyway
(to get the HTM Source)?

Thanks, Randy

"Dave" wrote:
Use remoting. In otherwords, expose your Form (which is MarshalByRefObject) over a TCP remoting channel and consume it in any other
..NET application by using client remoting. Make a public property for access to the browser control.

public AxWebBrowser Browser { get { return browserCtrl; } }

public TheForm()
{
System.Runtime.Remoting.Channels.Tcp.TcpChannel channel =
new System.Runtime.Remoting.Channels.Tcp.TcpChannel(10 24);

System.Runtime.Remoting.Channels.ChannelServices.R egisterChannel(channel);

System.Runtime.Remoting.RemotingServices.Connect(t ypeof(TheForm),
"tcp://localhost/theform:1024");
}

To consume the form, your project must have a reference to the assembly which contains TheForm:

public AXWebBrowser GetBrowserFromRemotingForm()
{
System.Runtime.Remoting.Channels.Tcp.TcpChannel channel =
new System.Runtime.Remoting.Channels.Tcp.TcpChannel(0) ;

System.Runtime.Remoting.Channels.ChannelServices.R egisterChannel(channel);

TheForm form = Activator.GetObject(typeof(TheForm), "tcp://localhost/theform:1024");
return form.WebBrowser;
}
I didn't test the code, so it will probably require some mods. Also, realize that when remoting an object such as a Form, all
properties must be serializable in some fashion, whether through declaration or inheritance. In this case it might make more sense
to remote an object to act as a proxy for the Form class that can return the WebBrowser control.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Randy" <Ra***@discussions.microsoft.com> wrote in message news:33**********************************@microsof t.com...
Hi,

ok, I found a way to connect to a running instance of an (external) Internet
Explorer and access - for example - the html source. That works fine!

But now I have running application with an embedded IE webBrowser Control.
Is there a possibility for my application to access the webBrowser control in
the other application, too?

Thanks in advance, Randy


Nov 17 '05 #3

P: n/a
Yes, there still is another solution: Interop.

Open Spy++ if you have it, and get the classname for the window you are after (the browser itself)

There are Win32 functions that allow code to access other processes, the main window, child windows, etc..

A function called FindWindowEx may be what your after:

http://msdn.microsoft.com/library/de...ndwindowex.asp

[DllImport("user32.dll")]
private static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string windowName);

You can specify the MainWindowHandle (which can be obtained via System.Diagnostics.Process) of the process containing the embedded
web browser as the "parent" parameter. childAfter may be IntPtr.Zero in your circumstance, but read the docs to find out.
className should be that of the WebBrowser control (that you obtained via Spy++), and windowName can be specified as null.

------------------------------------------------------------------------
I'm not sure how to get an IUnknown pointer from just a window handle, but I assume it' possible. If so, a bit of research will get
you there. Maybe somebody will be nice enough to post a solution for you...
------------------------------------------------------------------------

If you get the IUnknown pointer, you can use the following line of code to get an interface for the browser:

SHDocVw.IWebBrowser2 browser =
System.Runtime.InteropServices.Marshal.GetTypedObj ectForIUnknown(pUnk, typeof(SHDocVw.IWebBrowser2));

At this point, you can use your existing code to access the HTML.
GL :)

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Randy" <Ra***@discussions.microsoft.com> wrote in message news:16**********************************@microsof t.com...
Hi Dave,

thanks for your reply. Unfortunately the program with the embedded
webbrowser control is a "finished" application from another company (and I
don't have a chance to modify the source ;-)).

Is there a possibility to connect to the webbrowser control inside anyway
(to get the HTM Source)?

Thanks, Randy

"Dave" wrote:
Use remoting. In otherwords, expose your Form (which is MarshalByRefObject) over a TCP remoting channel and consume it in any
other
..NET application by using client remoting. Make a public property for access to the browser control.

public AxWebBrowser Browser { get { return browserCtrl; } }

public TheForm()
{
System.Runtime.Remoting.Channels.Tcp.TcpChannel channel =
new System.Runtime.Remoting.Channels.Tcp.TcpChannel(10 24);

System.Runtime.Remoting.Channels.ChannelServices.R egisterChannel(channel);

System.Runtime.Remoting.RemotingServices.Connect(t ypeof(TheForm),
"tcp://localhost/theform:1024");
}

To consume the form, your project must have a reference to the assembly which contains TheForm:

public AXWebBrowser GetBrowserFromRemotingForm()
{
System.Runtime.Remoting.Channels.Tcp.TcpChannel channel =
new System.Runtime.Remoting.Channels.Tcp.TcpChannel(0) ;

System.Runtime.Remoting.Channels.ChannelServices.R egisterChannel(channel);

TheForm form = Activator.GetObject(typeof(TheForm), "tcp://localhost/theform:1024");
return form.WebBrowser;
}
I didn't test the code, so it will probably require some mods. Also, realize that when remoting an object such as a Form, all
properties must be serializable in some fashion, whether through declaration or inheritance. In this case it might make more
sense
to remote an object to act as a proxy for the Form class that can return the WebBrowser control.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Randy" <Ra***@discussions.microsoft.com> wrote in message news:33**********************************@microsof t.com...
> Hi,
>
> ok, I found a way to connect to a running instance of an (external) Internet
> Explorer and access - for example - the html source. That works fine!
>
> But now I have running application with an embedded IE webBrowser Control.
> Is there a possibility for my application to access the webBrowser control in
> the other application, too?
>
> Thanks in advance, Randy
>


Nov 17 '05 #4

P: n/a
Hi Dave,

thanks a lot again....now all is much clearer for me...

------------------------------------------------------------------------
I'm not sure how to get an IUnknown pointer from just a window handle, but I assume it' possible. If so, a bit of research will get
you there. Maybe somebody will be nice enough to post a solution for you...
------------------------------------------------------------------------


unfortunately I could't find anything in the www that solves the problem
above... Could anybody help me? or does anybody know a complete script that
shows the way to solve the described problem?

Thanks a lot,

Randy
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.