Getting a reference to an "object" from the WebBrowser Control?

R

Robin Tucker

Hiya,

I'm using mshtml and the web browser control to embed an OLE object in my
..NET application.

What I want to do is get a reference to the "object" embedded therein:

The HTML looks something like this:

<html>
<body>
<object classid="clsid:260AACA0-F963-101B-8955-0000C0DCD465"
id="TgControl" width="100%" height="100%" border="1" ></object>
</body>
</html>

I am loading the above HTML with the Browser.Navigate2 command and all is
well. Now, I can fetch the Document Object Model of the web page using:

Dim myDoc As HTMLDocument = New HTMLDocumentClass
myDoc = CType(Browser.Document, HTMLDocument)

But how can I get a reference to the actual embedded item "TgControl" from
the object model?

Any hints greatly appreciated.



Robin
 
C

Cor Ligthert

Hi Robin,

When I was you I would start with it in VB.net with Option Strict of.

A sample to get the first href (This is all with early binding)
Watch typos or other errors I copied it from a class however not complete so
someparts can be very good wrong.

It is just to give you the idea.

I hope this helps?

Cor

myDoc = CType(Browser.Document, mshtml.IHTMLDocument2)
For i as integer = 0 To MyDoc.all.length - 1
Dim hElm as mshtml.IHTMLElement= DirectCast(MyDoc.all.item(i),
mshtml.IHTMLElement)
If (hElm.tagName = "a") Then
If Not DirectCast(hElm, mshtml.IHTMLAnchorElement).href Is Nothing
Then
hrefname = DirectCast(hElm,
mshtml.IHTMLAnchorElement).href.ToString
'do Something
End if
End If
next
 
R

Robin Tucker

Ok, I can see what you are doing here Cor, but the problem is I have an
object embedded of the class 260AACA0-F963-101B-8955-0000C0DCD465 - what I
want to do is get an IntPtr (or something) to this data blob so that I can
manipulate it while it is embedded in the web browser control.

By looking at the properties of "myDoc" with the debugger, I can see that
the HTML I have shown below results in the "Applet" collection having a
single item in it. I'm guessing this is something to do with my TgControl
object. Now what I want is to get access to this object so I can manipulate
it.

Does this make sense?

Thanks.
 
E

Elp

Robin Tucker said:
Hiya,

I'm using mshtml and the web browser control to embed an OLE object in my
.NET application.

What I want to do is get a reference to the "object" embedded therein:

No idea regarding your question but wouldn't it be easier to locate the .dll
or .ocx file containing this object and adding it directly on your form
instead of passing through the Web Browser control? Not all IE embeddable
objects can be ambedded in a Window Form but i've done that succesfully with
quite a few of them.
 
C

Cor Ligthert

Hi Robin,

Nice idea, however I would first try with that sample I gave you try to get
the information.
Probably is the equivalent from IHTMLAnchorElement for the object
IHTMLObjectElement.
I was currious and I typed it in in MSDN, and there it was :)

http://msdn.microsoft.com/library/d...shtml/reference/ifaces/objectelement/type.asp

Every element has something like that conform the DOM. From than I would do
that other step to get to the real applet object in mem, however from that I
donnot know how, although it sounds very interesting.

Cor
 
N

Nicholas Paldino [.NET/C# MVP]

Cor and Robin,

If you can get the IHTMLObjectElement interface, then you can use the
object property to get the actual object (and cast it to whatever you wish).

Hope this helps.
 
R

Robin Tucker

Cheers guys - I didn't see the object property. Actually, the
HTMLObjectElement class in mshtml does not have the object property,
although the IHTMLObjectElement interface does. This is what threw me!

Now its all working well. Thanks.

Nicholas Paldino said:
Cor and Robin,

If you can get the IHTMLObjectElement interface, then you can use the
object property to get the actual object (and cast it to whatever you wish).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Cor Ligthert said:
Hi Robin,

Nice idea, however I would first try with that sample I gave you try to get
the information.
Probably is the equivalent from IHTMLAnchorElement for the object
IHTMLObjectElement.
I was currious and I typed it in in MSDN, and there it was :)
http://msdn.microsoft.com/library/d...shtml/reference/ifaces/objectelement/type.asp
Every element has something like that conform the DOM. From than I would do
that other step to get to the real applet object in mem, however from
that
I
donnot know how, although it sounds very interesting.

Cor
 
R

Robin Tucker

oh please don't go there. That couldn't be done so we decided to create an
ActiveX control by adding the required interfaces to our OLE component. Hey
presto - shaggage! WinForms doesn't seem to like it very much, particularly
the out-of-processness of it. We get deadlock. So, as a last resort (well
not actually, a last resort would be scrapping the current OLE control and
totally re-writing the suite, which would take about 2 years) we are
embedding into a browser. If that doesn't work, embedding into Microsoft
Word within a browser, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top