Пожалуйста, попробуйте коды ниже.
CoInitialize(NULL);
CString strHTMLCode = "...";
CComPtr<IHTMLDocument2> pDoc;
HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (void**)&pDoc);
// get persist stream init
ComQIPtr<IPersistStreamInit> psi = doc;
// allocate memory
HGLOBAL hMem = ::GlobalAlloc(GPTR, strHTMLCode.GetLength() * sizeof(TCHAR));
::GlobalLock(hMem);
::CopyMemory(hMem, (LPCTSTR)strHTMLCode, strHTMLCode.GetLength() * * sizeof(TCHAR));
// create stream
IStream* stream = NULL;
HRESULT hr = ::CreateStreamOnHGlobal(hMem, FALSE, &stream);
if (SUCCEEDED(hr))
{
// load html string
psi->Load(stream);
stream->Release();
}
// free memory
::GlobalUnlock(hMem);
::GlobalFree(hMem);