[英]getElementsByTagName with IHTMLDocument3 randomly returns nothing
I'm trying to fill some form input fields in internet explorer from a c++ program but I'm facing a random bug that I hope is because of my code: 我正在尝试通过C ++程序在Internet Explorer中填充一些表单输入字段,但是我遇到了一个随机错误,我希望这是由于我的代码:
UINT msg = RegisterWindowMessage("WM_HTML_GETOBJECT");
LRESULT result = 0;
SendMessageTimeout(hwnd, msg, NULL, NULL, SMTO_ABORTIFHUNG, 10000, (PDWORD_PTR)&result);
if (!result)
return;
// get main document object
IHTMLDocument3 *doc = NULL;
ObjectFromLresult(result, IID_IHTMLDocument3, NULL, (void**)&doc);
if (!doc)
return;
VARIANT varint, varstr;
varint.vt = VT_I4;
varstr.vt = VT_BSTR;
IHTMLElementCollection* pElemCollections=NULL;
if (FAILED(doc->getElementsByTagName(L"input", &pElemCollections)))
return;
long nelm;
pElemCollections->get_length(&nelm);
...
At this last line and with the same HWND at the same page I sometimes get the good number or input fields and often get 0 for nelm. 在这最后一行,并且在同一页面上使用相同的HWND,我有时会得到较好的数字或输入字段,并且对于nelm通常会得到0。
Do you see something wrong in my code or is it a bug ? 您是否在我的代码中看到错误或错误? Note that I verified that the HWND is correct, and the return
are never called. 请注意,我已验证HWND是正确的,并且永远不会调用该return
。
Thanks 谢谢
I have no more problem by doing that: 通过这样做,我没有更多问题:
UINT msg = RegisterWindowMessage("WM_HTML_GETOBJECT");
LRESULT result = 0;
SendMessageTimeout(hwnd, msg, NULL, NULL, SMTO_ABORTIFHUNG, 10000, (PDWORD_PTR)&result);
if (!result)
return;
// get main document object
IHTMLDocument3 *doc = NULL;
ObjectFromLresult(result, IID_IHTMLDocument3, NULL, (void**)&doc);
if (!doc)
return;
CComVariant varint;
CComVariant varstr;
IHTMLElementCollection* pElemCollections=NULL;
CComBSTR name(L"input")
if (FAILED(doc->getElementsByTagName(name, &pElemCollections)))
return;
long nelm;
pElemCollections->get_length(&nelm);
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.