VB.Net - Can't get type for "MSHTML.HTMLDocumentsEvents2"

M

miktro

I have an VB.Net desktop application where I am hosting a WebBrowser.

I need to interact with the events in the browser.
I encountered the normal problem of, after adding events the normal click
on the browser didn't work (in particular you can't enter text into
textareas).

I found the Microsoft KB article 311284 - "How to handle document evetns
in VB.Net" - and implemented the code.

However when I run the application I get the following error:

--------------Error Message------------------------------------------
Doc Complete Error: Could not load type mshtml.HTMLDocumentEvents2 from
assembly WindowsApplication1, Version=1.0.2155.37390, Culture=neutral,
PublicKeyToken=null.
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean
ignoreCase)
at WindowsApplication1.IEEvents.DocumentComplete(Object pDisp, Object&
URL) in D:\WinXP\jobs\WebBrowser\HTMEvents\VB\IEEvents.vb:line 204
--------------------------------------------------------------------
where lines 203-204 are:
--------------------------------------------------------------------
203: Dim tt As System.Type
204: tt = System.Type.GetType("mshtml.HTMLDocumentEvents2", True, True)
--------------------------------------------------------------------

Why can't the application find 'mshtml.HTMLdocumentevents2'?
And what do I need to change / add to the application
(like building an interop for mshtml?).


Any help greatly appreciated.

Mike
 
C

Cor Ligthert [MVP]

Miktro,

Which webbroswer are you using the VB2005 or VB2003 version.

They are complete different in use while the documentation on MSDN is still
all VB2005

Cor
 
M

miktro

Miktro,

Which webbroswer are you using the VB2005 or VB2003 version.

They are complete different in use while the documentation on MSDN is
still all VB2005

Cor

I'm using VB2003 - and had the same problem earlier with vb2002.
I have done many hours of google searching and found a few solutions to
thsi problem (mainly in C#) that use the same approach of using a
delegate to duplicate the event handling.
I've also found a few messages claiming to have usccessfully used the MS
KB VB.Net code.

Anyway - the question still is:

203: Dim tt As System.Type
204: tt = System.Type.GetType("mshtml.HTMLDocumentEvents2", True, True)
--------------------------------------------------------------------

Why can't the application find 'mshtml.HTMLdocumentevents2'?
And what do I need to change / add to the application?


Mike
 
C

Cor Ligthert [MVP]

Miktro,

In my opinion is it if you use MSHTML inside the browser that you should use
the browser events

However to set text in the browser you have to set this.
\\\
Private Sub AxWebBrowser1_NavigateComplete2(ByVal sender As System.Object,
ByVal e As _
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles _
AxWebBrowser1.NavigateComplete2
oDocument = DirectCast(DirectCast(e.pDisp, SHDocVw.WebBrowser).Document, _
mshtml.IHTMLDocument2)
DirectCast(DirectCast(e.pDisp, SHDocVw.WebBrowser).Document, _
mshtml.IHTMLDocument2).designMode = "On"
End Sub
///

I hope this helps,

Cor
 
M

miktro

Miktro,

In my opinion is it if you use MSHTML inside the browser that you
should use the browser events

However to set text in the browser you have to set this.
\\\
Private Sub AxWebBrowser1_NavigateComplete2(ByVal sender As
System.Object, ByVal e As _
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles _
AxWebBrowser1.NavigateComplete2
oDocument = DirectCast(DirectCast(e.pDisp,
SHDocVw.WebBrowser).Document, _ mshtml.IHTMLDocument2)
DirectCast(DirectCast(e.pDisp, SHDocVw.WebBrowser).Document, _
mshtml.IHTMLDocument2).designMode = "On"
End Sub
///

I hope this helps,

Cor

Thanks Cor - I'm not sure if this helps as I can enter text perfectly OK
- as long as I don't intercept events on the document directly.
But I'll keep it in mind if I hit any later problems.

I am intercepting the mshtml.htmldocumentevents2 events (the whole
pointof the excercise is ot get hold of the onclick event etc.)
and I am using the microsoft example code to construct an additional
delegate to re-cast and handle the interface - now SUCCESSFUL!

I found the GUID I need as a string by searching
\HKEY_CLASSES_ROOT\interface for the string "htmldocumentevents2"
but I would like to know if there is a way of doing this from within
vb.net - without hardcoding the guid into the code.

Anyway - everything seems to be working perfectly now.
My web browser behaves as normal - and I can intercept all the events
with VB.Net code without changing the browser behaviour.
 

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