saveiwebbrowser2ihtmldocument2

IPersistStreamInit::Save() not working in IE9?


This code worked for IE8 and earlier. For IE9 it seems that IPersistStreamInit::Save() returns E_NOTIMPL. Any help is greatly appreciated!

HRESULT CHtmlCtrl::GetDocumentHTML(CString& strHTML) const
{
    HRESULT hr = E_NOINTERFACE;

    CComPtr<IHTMLDocument2> spHTMLDocument;
    GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&spHTMLDocument);
    if (spHTMLDocument)
    {
        CComQIPtr<IPersistStreamInit> spPSI;
        spPSI = spHTMLDocument;
        if (spPSI)
        {
            CStreamOnCString stream;
            hr = spPSI->Save(static_cast<IStream*>(&stream), FALSE);
            if (hr == S_OK)
            {
                if (!stream.CopyData(strHTML))
                    hr = E_OUTOFMEMORY;
            }
        }
    }

    return hr;
}

Solution

  • Seems to be a bug in the MFC as described and confirmed here. Fixed in Visual Studio 2012 RTM.