FIX: Type Mismatch for Document.parentWindowID: Q188764
|
In a Visual Basic 5.0 application that is accessing the Internet Explorer object model, setting a variable declared as HTMLWindow2 equal to Document.parentWindow, results in a type mismatch.
Declare your window variable as IHTMLWindow2.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Microsoft Internet Explorer 5.
When accessing the document object model in a Visual Basic application, it
is sometimes desirable to access the window object through the parentWindow
property of the Document object. For example, you may be hosting the
WebBrowser control in your application and wish to access a method or
property of the window object associated with the WebBrowser control.
If you declare your window variable as HTMLWindow2, you will receive a type
mismatch error from Visual Basic when setting your variable equal to
WebBrowser1.Document.parentWindow. This occurs only if you have installed
the Internet Explorer 5.0 Developer Preview.
Option Explicit
Public doc As HTMLDocument
Public win As HTMLWindow2
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.microsoft.com"
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, _
URL As Variant)
Set doc = WebBrowser1.Document
Set win = doc.parentWindow ' Gives Type mismatch error
End Sub
The resolution is to declare your window variable as IHTMLWindow2. Here is
the Visual Basic code that works in the Internet Explorer 5.0 Developer
Preview:
Option Explicit
Public doc As HTMLDocument
Public win As IHTMLWindow2
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.microsoft.com"
End Sub
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, _
URL As Variant)
Set doc = WebBrowser1.Document
Set win = doc.parentWindow
End Sub
Please note that you must insert the "Microsoft Internet Controls"
component into your project and set a reference to Mshtml.tlb. The one
disadvantage of this workaround is that you will not be able to sink events
for the window object.
For more information, please see the MSDN Web Workshop:
http://msdn.microsoft.com/workshop/default.aspFor additional information, please see the following article(s) in the Microsoft Knowledge Base:
Q188020 BETA-PRB: Type Information not Found in Mshtml.dll
Additional query words:
Keywords : kbnokeyword kbIE500fix kbIEdp1bug
Version :
Platform :
Issue type : kbprb
Last Reviewed: April 9, 1999