FIX: Type Mismatch for Document.parentWindow

ID: Q188764


The information in this article applies to:
  • Microsoft Internet Explorer (Programming) version 5.0dp1


SYMPTOMS

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.


RESOLUTION

Declare your window variable as IHTMLWindow2.


STATUS

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.


MORE INFORMATION

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.

Steps to Reproduce Behavior

The following Visual Basic code demonstrates this problem:

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.


REFERENCES

For more information, please see the MSDN Web Workshop:

http://msdn.microsoft.com/workshop/default.asp
For 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
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.