Microsoft KB Archive/271868

= BUG: IPersistStreamInit Not Available for a FRAME in a FRAMESET =

Article ID: 271868

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 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.



Steps to Reproduce Behavior
 Create a new Microsoft Foundation Class Library (MFC) single-document interface (SDI) application that derives from the CHTMLView class.  Modify the OnInitialUpdate of CHTMLView-derived class to browse to a page that uses frames: void CMFCPersistLoadView::OnInitialUpdate {   CHtmlView::OnInitialUpdate;

Navigate2(_T(&quot;http://www.news.com/&quot;),NULL,NULL); }                     Override the DocumentComplete virtual method in CHTMLView:
 * 1) 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(&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(&pStmInit)); if (FAILED(hr) || !pStmInit) { goto cleanup; }

cleanup: RELEASE(pBrowser); RELEASE(pStmInit); RELEASE(pDispDoc);

}                    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.</ol>

<div class="references_section">