PC Review


Reply
Thread Tools Rate Thread

Connecting to a running instance of an embedded webBrowser control

 
 
=?Utf-8?B?UmFuZHk=?=
Guest
Posts: n/a
 
      4th May 2005
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

 
Reply With Quote
 
 
 
 
Dave
Guest
Posts: n/a
 
      4th May 2005
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(1024);

System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel);

System.Runtime.Remoting.RemotingServices.Connect(typeof(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.RegisterChannel(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" <(E-Mail Removed)> wrote in message news:3332CD6B-ABF6-40FE-A0D2-(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
=?Utf-8?B?UmFuZHk=?=
Guest
Posts: n/a
 
      4th May 2005
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(1024);
>
> System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel);
>
> System.Runtime.Remoting.RemotingServices.Connect(typeof(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.RegisterChannel(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" <(E-Mail Removed)> wrote in message news:3332CD6B-ABF6-40FE-A0D2-(E-Mail Removed)...
> > 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
> >

>
>
>

 
Reply With Quote
 
Dave
Guest
Posts: n/a
 
      4th May 2005
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.GetTypedObjectForIUnknown(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" <(E-Mail Removed)> wrote in message news:1695A5B8-463B-419F-A017-(E-Mail Removed)...
> 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(1024);
>>
>> System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel);
>>
>> System.Runtime.Remoting.RemotingServices.Connect(typeof(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.RegisterChannel(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" <(E-Mail Removed)> wrote in message news:3332CD6B-ABF6-40FE-A0D2-(E-Mail Removed)...
>> > 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
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?UmFuZHk=?=
Guest
Posts: n/a
 
      5th May 2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WebBrowser instance in Windows 7? Tom Whittaker Microsoft C# .NET 1 14th Aug 2009 07:34 AM
Single-instance app: how to force running instance window to foreground? Jen Microsoft C# .NET 6 3rd Apr 2007 10:04 PM
.Net 2.0 - WebBrowser control embedded in IE causes problems L. Chernov Microsoft Dot NET Framework 1 18th Jul 2006 02:27 PM
.Net 2.0 - WebBrowser control embedded in IE causes problems L. Chernov Microsoft ASP .NET 1 18th Jul 2006 02:27 PM
Connecting to Database from Windows Control running in ASP.Net webform =?Utf-8?B?ZWoxMDA4?= Microsoft ASP .NET 10 2nd Jul 2004 10:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:53 PM.