I'm using IHTMLDocument2::write()
as described here in order to load HTML from memory into an IWebBrowser2
instance. The code is shown below:
#include <MsHTML.h>
void CMyDlg::WriteHTML(const wchar_t* html)
{
IDispatch* pHtmlDoc = m_explorer.get_Document();
if (!pHtmlDoc)
return;
CComPtr<IHTMLDocument2> doc2;
doc2.Attach((IHTMLDocument2*)pHtmlDoc);
if (!doc2)
return;
SAFEARRAY* psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
if (!psaStrings)
return;
BSTR bstr = SysAllocString(html);
if (bstr)
{
VARIANT* param;
HRESULT hr = SafeArrayAccessData(psaStrings, (LPVOID*)¶m);
if (SUCCEEDED(hr))
{
param->vt = VT_BSTR;
param->bstrVal = bstr;
hr = SafeArrayUnaccessData(psaStrings);
if (SUCCEEDED(hr))
{
doc2->write(psaStrings);
doc2->close();
}
}
}
if (psaStrings)
SafeArrayDestroy(psaStrings);
}
This works as I'd expect (the HTML is loaded). However none of the linked resources (images etc) can be found because there is no "base URL" from which to load them.
How can I set the base URL for the document such that if there is an image foo.png at "http://bar.com/baz/foo.png", the image can be found via a href of "baz/foo.png" within the loaded document?