FIX: Type Mismatch for Document.parentWindow |
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 on developing Web-based solutions for Internet Explorer, please see the following Web sites:
http://msdn.microsoft.com/workshop/default.asp
http://support.microsoft.com/highlights/iep.asp?FR=0&SD=MSDN
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 kbGrpDSInet kbie500fix kbiedp1bug
Issue type : kbbug
Technology : kbIEsearch kbAudDeveloper kbSDKIESearch kbSDKIE500
Last Reviewed: May 16, 2000 |