BUG: IPersistStreamInit Not Available for a FRAME in a FRAMESET (271868)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q271868

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.

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).

STATUS

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

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.

REFERENCES

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

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbBug kbpending kbWebBrowser KB271868