Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2009, 03:44 PM
Authorized User
 
Join Date: Jan 2004
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to adyrotaru
Default Accessing and using an ActiveX from inside a HTML page hosted inside a WebBrowser con

Hi.

I have a page that is hosted by a WebBrowser control that is "hosted"
by a WinForms.
The page displays an ActiveX control.
I need, from C# code to access and manipulate the ActiveX control. I
already managed to get a reference to the HTMLObjectElementClass
object, but I need to somehow get the right reference to the ActiveX
object itself so that I will be able to invoke directly it's methods,
like:


myActiveX.Load();


To be more specific. Let's say we have this HTML page:


Code:
 
 
 
 
 

<html>
<BODY>
<table>
<tr>
<td>
<object classid=clsid: 464623dc-4d81-11dc-8314-0800200c9a66 id='myControl' width='660', height='500'>
<PARAM NAME='Host' VALUE='192.168.3.100'/>
<PARAM NAME='HttpPort' VALUE='80'/>
<PARAM NAME='RTSPPort' VALUE='554'/>
<PARAM NAME='RTSPoverHTTP' VALUE='0'/>
<PARAM NAME='RTSPoverTCP' VALUE='0'/>
<PARAM NAME='VFormat' VALUE='96'/>
<PARAM NAME='G72640PT' VALUE='98'/>
<PARAM NAME='G72632PT' VALUE='97'/>
<PARAM NAME='G72624PT' VALUE='99'/>
<PARAM NAME='G72616P' VALUE='100'/>
<PARAM NAME='AMRPT' VALUE='101'/>
<PARAM NAME='UIMode' VALUE='0'/>
<PARAM NAME='MediaUsername' VALUE='z'/>
<PARAM NAME='MediaPassword' VALUE='z'/>
</object>
</td>
</tr>
</table>
</body>
</html>
I get a reference to the hmtl element like this:

Code:
HTMLDocumentClass doc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass;
HTMLObjectElementClass myControl = doc.all.item("myControl", 0) as HTMLObjectElementClass;
From myControl I need to get a reference to the underlying COM object
with the appropriate type so that I can call methods like this:

Code:
myControlCOM.Load();
Thanks.
__________________
smile... tomorrow will be better

Last edited by adyrotaru; June 25th, 2009 at 03:51 PM.. Reason: formatting
 
Old June 25th, 2009, 04:01 PM
Authorized User
 
Join Date: Jan 2004
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to adyrotaru
Default

Quote:
Originally Posted by adyrotaru View Post
Hi.

I have a page that is hosted by a WebBrowser control that is "hosted"
by a WinForms.
The page displays an ActiveX control.
I need, from C# code to access and manipulate the ActiveX control. I
already managed to get a reference to the HTMLObjectElementClass
object, but I need to somehow get the right reference to the ActiveX
object itself so that I will be able to invoke directly it's methods,
like:


myActiveX.Load();


To be more specific. Let's say we have this HTML page:


Code:
 
 
 
 
 

<html>
<BODY>
<table>
<tr>
<td>
<object classid=clsid: 464623dc-4d81-11dc-8314-0800200c9a66 id='myControl' width='660', height='500'>
<PARAM NAME='Host' VALUE='192.168.3.100'/>
<PARAM NAME='HttpPort' VALUE='80'/>
<PARAM NAME='RTSPPort' VALUE='554'/>
<PARAM NAME='RTSPoverHTTP' VALUE='0'/>
<PARAM NAME='RTSPoverTCP' VALUE='0'/>
<PARAM NAME='VFormat' VALUE='96'/>
<PARAM NAME='G72640PT' VALUE='98'/>
<PARAM NAME='G72632PT' VALUE='97'/>
<PARAM NAME='G72624PT' VALUE='99'/>
<PARAM NAME='G72616P' VALUE='100'/>
<PARAM NAME='AMRPT' VALUE='101'/>
<PARAM NAME='UIMode' VALUE='0'/>
<PARAM NAME='MediaUsername' VALUE='z'/>
<PARAM NAME='MediaPassword' VALUE='z'/>
</object>
</td>
</tr>
</table>
</body>
</html>
I get a reference to the hmtl element like this:

Code:
HTMLDocumentClass doc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass;
HTMLObjectElementClass myControl = doc.all.item("myControl", 0) as HTMLObjectElementClass;
From myControl I need to get a reference to the underlying COM object
with the appropriate type so that I can call methods like this:

Code:
myControlCOM.Load();
Thanks.
Hi all
Just found my answer here:

http://www.sahirshah.com/CSharp/objcall.html

Hope it helps.
__________________
smile... tomorrow will be better
 
Old June 25th, 2009, 04:21 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I don't know if this would work, but it might be better (if it does work) to try using HtmlElement.InvokeMember:

Code:
HtmlDocument doc = webBrowser1.Document;
HtmlElement aX = doc.GetElementById("myControl");
aX.InvokeMember("Load");
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
adyrotaru (June 25th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
html part inside xml RoeZ XSLT 3 November 28th, 2007 08:18 AM
Problem accessing global variable inside functions jedijr88 Beginning PHP 3 June 29th, 2007 12:51 PM
Render HTML inside CDATA with XSL c2c XSLT 0 September 10th, 2006 11:10 AM
change page encoding in WebBrowser ActiveX control alexxx_ltd Visual C++ 2 December 16th, 2004 07:08 PM
databound grids with html controls inside badgolfer ASP.NET 1.0 and 1.1 Basics 1 September 25th, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.