此代码适用于IE8及更早版本。对于IE9, IPersistStreamInit::Save()返回E_NOTIMPL。任何帮助都非常感谢!
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;
}
似乎是MFC中的一个bug,正如这里所描述和确认的。修复了Visual Studio 2012 RTM