EDN Admin
Well-known member
hi,all, I have a piece of html source like this:
<div style="color:black; background-color:white
<pre><span style="color:blue <<span style="color:#a31515 FONT <span style="color:red color<span style="color:blue =<span style="color:blue #5a6571<span style="color:blue >Beverly Mitchell<span style="color:blue </<span style="color:#a31515 FONT<span style="color:blue > <span style="color:blue <<span style="color:#a31515 FONT <span style="color:red color<span style="color:blue =<span style="color:blue #5a6571<span style="color:blue >Shawnee Smith<span style="color:blue </<span style="color:#a31515 FONT<span style="color:blue > <span style="color:blue <<span style="color:#a31515 FONT <span style="color:red color<span style="color:blue =<span style="color:blue #5a6571<span style="color:blue >Glenn Plummer<span style="color:blue </<span style="color:#a31515 FONT<span style="color:blue > <span style="color:blue <<span style="color:#a31515 NOBR<span style="color:blue >more <span style="color:red ><span style="color:red ><span style="color:blue </<span style="color:#a31515 NOBR<span style="color:blue >[/code]
now i tried to retrieve the "color" value, like this:
<div style="color:black; background-color:white
<pre>MSHTML::IHTMLDocument2Ptr htmDoc1 = NULL;
SAFEARRAY *psaStrings1 = SafeArrayCreateVector(VT_VARIANT, 0, 1);
CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (<span style="color:blue void**) &htmDoc1);
VARIANT *param1 = NULL;
HRESULT hr = SafeArrayAccessData(psaStrings1, (LPVOID*)¶m1);
param1->vt = VT_BSTR;
param1->bstrVal = SysAllocString(varSrc1.bstrVal);
hr = SafeArrayUnaccessData(psaStrings1);
hr = htmDoc1->write(psaStrings1);
MSHTML::IHTMLElementPtr pElemBody1 = NULL;
MSHTML::IHTMLDOMNodePtr pHTMLBodyDOMNode1 =NULL;
hr = htmDoc1->get_body(&pElemBody1);
<span style="color:blue if(SUCCEEDED(hr))
{
hr = pElemBody1->QueryInterface(IID_IHTMLDOMNode,(<span style="color:blue void**)&pHTMLBodyDOMNode1);
<span style="color:blue if(SUCCEEDED(hr))
{
ProcessDomNodeSmartWrapper(pHTMLBodyDOMNode1, ProcTgtTagStrVec);
}
}
<span style="color:blue long lLength = 0;
MSHTML::IHTMLElementCollectionPtr pElemColl1 = NULL;
MSHTML::IHTMLElementPtr pChElem1 = NULL;
MSHTML::IHTMLStylePtr pStyle1 = NULL;
IDispatchPtr ppvdisp1 = NULL;
hr = htmDoc1->get_all(&pElemColl1);
hr = pElemColl1->get_length(&lLength);
<span style="color:blue for(<span style="color:blue long i = 0; i < lLength; i++)
{
_variant_t name(i);
_variant_t index(i);
ppvdisp1 = pElemColl1->item(name, index);
<span style="color:blue if(ppvdisp1 && SUCCEEDED(hr))
{
hr = ppvdisp1->QueryInterface(IID_IHTMLElement, (<span style="color:blue void **)&pChElem1);
<span style="color:blue if(pChElem1 && SUCCEEDED(hr))
{
BSTR bstrTagName = NULL;
pChElem1->get_tagName(&bstrTagName);
hr = pChElem1->get_style(&pStyle1);
<span style="color:blue if(pStyle1 && SUCCEEDED(hr))
{
_variant_t varFtCol;
hr = pStyle1->get_color(&varFtCol);
<span style="color:blue if(hr = S_OK && varFtCol)
{
hmStyles1[wstring(varFtCol.bstrVal)] = L<span style="color:#a31515 "FontColor";
}
}
<span style="color:blue if(bstrTagName)
SysFreeString(bstrTagName);
} <span style="color:green // if pStyle && SUCCEEDED(hr)
}<span style="color:green //if ppvdisp && SUCCEEDED(hr)
}<span style="color:green //for[/code]
but i can never get the "color" value - varFtCol.bstrVal is a bad pointer when i debug the program, so whats wrong?
cheers
daiyue
<br/>
<br/>
View the full article
<div style="color:black; background-color:white
<pre><span style="color:blue <<span style="color:#a31515 FONT <span style="color:red color<span style="color:blue =<span style="color:blue #5a6571<span style="color:blue >Beverly Mitchell<span style="color:blue </<span style="color:#a31515 FONT<span style="color:blue > <span style="color:blue <<span style="color:#a31515 FONT <span style="color:red color<span style="color:blue =<span style="color:blue #5a6571<span style="color:blue >Shawnee Smith<span style="color:blue </<span style="color:#a31515 FONT<span style="color:blue > <span style="color:blue <<span style="color:#a31515 FONT <span style="color:red color<span style="color:blue =<span style="color:blue #5a6571<span style="color:blue >Glenn Plummer<span style="color:blue </<span style="color:#a31515 FONT<span style="color:blue > <span style="color:blue <<span style="color:#a31515 NOBR<span style="color:blue >more <span style="color:red ><span style="color:red ><span style="color:blue </<span style="color:#a31515 NOBR<span style="color:blue >[/code]
now i tried to retrieve the "color" value, like this:
<div style="color:black; background-color:white
<pre>MSHTML::IHTMLDocument2Ptr htmDoc1 = NULL;
SAFEARRAY *psaStrings1 = SafeArrayCreateVector(VT_VARIANT, 0, 1);
CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (<span style="color:blue void**) &htmDoc1);
VARIANT *param1 = NULL;
HRESULT hr = SafeArrayAccessData(psaStrings1, (LPVOID*)¶m1);
param1->vt = VT_BSTR;
param1->bstrVal = SysAllocString(varSrc1.bstrVal);
hr = SafeArrayUnaccessData(psaStrings1);
hr = htmDoc1->write(psaStrings1);
MSHTML::IHTMLElementPtr pElemBody1 = NULL;
MSHTML::IHTMLDOMNodePtr pHTMLBodyDOMNode1 =NULL;
hr = htmDoc1->get_body(&pElemBody1);
<span style="color:blue if(SUCCEEDED(hr))
{
hr = pElemBody1->QueryInterface(IID_IHTMLDOMNode,(<span style="color:blue void**)&pHTMLBodyDOMNode1);
<span style="color:blue if(SUCCEEDED(hr))
{
ProcessDomNodeSmartWrapper(pHTMLBodyDOMNode1, ProcTgtTagStrVec);
}
}
<span style="color:blue long lLength = 0;
MSHTML::IHTMLElementCollectionPtr pElemColl1 = NULL;
MSHTML::IHTMLElementPtr pChElem1 = NULL;
MSHTML::IHTMLStylePtr pStyle1 = NULL;
IDispatchPtr ppvdisp1 = NULL;
hr = htmDoc1->get_all(&pElemColl1);
hr = pElemColl1->get_length(&lLength);
<span style="color:blue for(<span style="color:blue long i = 0; i < lLength; i++)
{
_variant_t name(i);
_variant_t index(i);
ppvdisp1 = pElemColl1->item(name, index);
<span style="color:blue if(ppvdisp1 && SUCCEEDED(hr))
{
hr = ppvdisp1->QueryInterface(IID_IHTMLElement, (<span style="color:blue void **)&pChElem1);
<span style="color:blue if(pChElem1 && SUCCEEDED(hr))
{
BSTR bstrTagName = NULL;
pChElem1->get_tagName(&bstrTagName);
hr = pChElem1->get_style(&pStyle1);
<span style="color:blue if(pStyle1 && SUCCEEDED(hr))
{
_variant_t varFtCol;
hr = pStyle1->get_color(&varFtCol);
<span style="color:blue if(hr = S_OK && varFtCol)
{
hmStyles1[wstring(varFtCol.bstrVal)] = L<span style="color:#a31515 "FontColor";
}
}
<span style="color:blue if(bstrTagName)
SysFreeString(bstrTagName);
} <span style="color:green // if pStyle && SUCCEEDED(hr)
}<span style="color:green //if ppvdisp && SUCCEEDED(hr)
}<span style="color:green //for[/code]
but i can never get the "color" value - varFtCol.bstrVal is a bad pointer when i debug the program, so whats wrong?
cheers
daiyue
<br/>
<br/>
View the full article