Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: IPersistStreamInit Not Available for a FRAME in a FRAMESET


View products that this article applies to.

This article was previously published under Q271868

↑ Back to the top


Symptoms

In a Microsoft Visual C++ WebBrowser host or similar application, when you call the QueryInterface method for the IPersistStreamInit interface on a FRAME in a FRAMESET, it returns E_NOINTERFACE. When you query for other standard persistence interfaces (IPersistStream, IPersistFile, IPersistMemory), you receive the same error.

This problem does not occur in Internet Explorer version 5.01 and earlier.

↑ Back to the top


Resolution

There are two ways to work around this problem:
  • Create a new HTML file inside of the FRAME. -or-

  • Read the existing contents of the current HTML file.

Create a New HTML File

You can use the IHTMLDocument2::write method to add content to the WebBrowser control. Make sure that you call the IHTMLDocument2::open method first and the IHTMLDocument2::close method last. To obtain the IHTMLDocument2 interface, perform the following steps:
  1. Load a blank file into the WebBrowser control.
  2. Call the IWebBrowser2::get_Document method to obtain the IDispatch interface of the document.
  3. Call QueryInterface on the IDispatch pointer, and ask for IHTMLDocument2.
This code does not work for Internet Explorer versions 5.01 and earlier because these versions cannot obtain the IWebBrowser2 control (and therefore IHTMLDocument2) of a FRAME that was created using IHTMLDocument2::write.

Microsoft recommends that you use version detection in your hosts to switch between solutions, using this workaround to create a new file in Internet Explorer 5.5, and using IPersistStreamInit in earlier versions of the browser. You can obtain the browser's full version number from the following registry value:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version

Read Source for the Current HTML File

To obtain this original HTML source without IPersistStreamInit, you can use the UrlOpenStream function from the URL Moniker application programming interface (API).

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Create a new Microsoft Foundation Class Library (MFC) single-document interface (SDI) application that derives from the CHTMLView class.
  2. Modify the OnInitialUpdate of CHTMLView-derived class to browse to a page that uses frames:
    void CMFCPersistLoadView::OnInitialUpdate()
    {
    	CHtmlView::OnInitialUpdate();
    
    	Navigate2(_T("http://www.news.com/"),NULL,NULL);
    }
    					
  3. Override the DocumentComplete virtual method in CHTMLView:
    #define RELEASE(ptr) if (ptr) { ptr->Release(); ptr = NULL; }
    
    void CMFCPersistLoadView::DocumentComplete(IDispatch *pDisp, VARIANT *URL) {
    	HRESULT hr = S_OK;
    	IWebBrowser2 *pBrowser = NULL;
    	IPersistStreamInit *pStmInit = NULL;
    	IDispatch *pDispDoc = NULL;
    
    	hr = pDisp->QueryInterface(IID_IWebBrowser2, reinterpret_cast<void **>(&pBrowser));
    	if (FAILED(hr) || !pBrowser) {
    		goto cleanup;
    	}
    
    	hr = pBrowser->get_Document(&pDispDoc);
    	if (FAILED(hr) || !pDisp) {
    		goto cleanup;
    	}
    
    	hr = pDisp->QueryInterface(IID_IPersistStreamInit, reinterpret_cast<void **>(&pStmInit));
    	if (FAILED(hr) || !pStmInit) {
    		goto cleanup;
    	}	
    
    cleanup:
    	RELEASE(pBrowser);
    	RELEASE(pStmInit);
    	RELEASE(pDispDoc);
    
    }
    					
  4. Put a breakpoint on the DocumentComplete event, and step through the code. For FRAME URLs, when you query the document's IDispatch for IPersistStreamInit, it returns E_NOINTERFACE.

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Keywords: KB271868, kbwebbrowser, kbpending, kbbug

↑ Back to the top

Article Info
Article ID : 271868
Revision : 5
Created on : 5/11/2006
Published on : 5/11/2006
Exists online : False
Views : 333