Home > Software engineering >  Turn thread calls com collapse problem inside
Turn thread calls com collapse problem inside

Time:12-10

Function is inside the webbrowser click login button, text access to elements in traverse elements, get_innerText () collapse,
First this in the main line, write not in the thread, I have been at the beginning of the thread added CoInitializeEx (0, COINIT_APARTMENTTHREADED);

Specific code:
 
//take out the eligible elements of traverse webbrowser
IHTMLElement * getElementByName (CComQIPtr{
CComQIPtr PelColl;
Retrieves the hr=pDoc3 - & gt; The getElementsByTagName ((_bstr_t) tagName, & amp; PelColl);
If (FAILED (hr) | | pelColl==NULL)
{
return NULL;
}

Long len=0;
PelColl - & gt; Get_length (& amp; Len);

For (long I=0; I & lt; Len. I++)
{
_variant_t index=I;
Pdisp IDispatch *=NULL;
PelColl - & gt; The item (index, index, & amp; Pdisp);
If (pdisp==NULL)
{
continue;
}
Pele IHTMLElement *=NULL;
Pdisp - & gt; QueryInterface (IID_IHTMLElement, (LPVOID *) (& amp; Pele));
If (pele)
{
BSTR b;
//here collapse, & amp; The value of b is 0 XCCCCCCCC
Pele - & gt; Get_innerText (& amp; B);
_bstr_t BSTR=b;
If (BSTR. Length () & amp; & STRCMP (BSTR, name)==0)
{
Return pele.
}
Pele - & gt; Release ();
}
Pdisp - & gt; Release ();

}

return NULL;
}

//thread function
DWORD __stdcall threadLoginbd (LPVOID lp)
{
Retrieves the hr=CoInitializeEx (0, COINIT_APARTMENTTHREADED);
If (FAILED (hr))
{
TRACE (" 1 ");
}

PDlg CwebbrowserDlg *=(CwebbrowserDlg *) lp;
CExplorer1 * pIe=& amp; (pDlg - & gt; M_ie);

CComQIPtr
//get elements and then click
Pele IHTMLElement *=getElementByName (pDoc3, "a", "login");
If (pele)
{
Pele - & gt; Click ();
Pele - & gt; Release ();
TRACE (" 3 ");
}

CoUninitialize ();
return 0;
}



Don't understand defines a BSTR b, how is the address of the 0 XCCCCCCCC,
  • Related