OLECHAR szHTML[] = OLESTR("<HTML><BODY>Hello World!</BODY></HTML>");
IHTMLDocument2 *pDoc = NULL;
CoInitialize(NULL);
CoCreateInstance(CLSID_HTMLDocument,
NULL,
CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2,
(LPVOID *)&pDoc);
if(pDoc)
{
IPersistStreamInit *pPersist = NULL;
pDoc->QueryInterface(IID_IPersistStreamInit, (LPVOID *) &pPersist);
if(pPersist)
{
IMarkupServices *pMarkSvr = NULL;
pPersist->InitNew();
pPersist->Release();
pDoc->QueryInterface(IID_IMarkupServices, (LPVOID *)&pMarkSvr);
if(pMarkSvr)
{
IMarkupContainer *pMkContainer = NULL;
IMarkupPointer *pMkStart = NULL;
IMarkupPointer *pMkFinish = NULL;
pMarkSvr->CreateMarkupPointer(&pMkStart);
pMarkSvr->CreateMarkupPointer(&pMkFinish);
pMarkSvr->ParseString(szHTML, 0, &pMkContainer, pMkStart, pMkFinish);
if(pMkContainer)
{
IHTMLDocument2 *pNewDoc = NULL;
pMkContainer->QueryInterface(IID_IHTMLDocument, (LPVOID *)&pNewDoc);
if(pNewDoc)
{
// do anything with pNewDoc, in this case
// get the body innerText.
IHTMLElement *pBody;
pNewDoc->get_body(&pBody);
if(pBody)
{
BSTR strText;
pBody->get_innerText(&strText);
ShowMessage(strText);
pBody->Release();
SysFreeString(strText);
}
pNewDoc->Release();
}
pMkContainer->Release();
}
if(pMkStart)
pMkStart->Release();
if(pMkFinish)
pMkFinish->Release();
pMarkSvr->Release();
}
}
pDoc->Release();
}
CoUninitialize();
参考: http: //www.codeguru.com/cpp/in/ieprogram/article.php/c4385/Lightweight-HTML-Parsing-Using-MSHTML.htm#more