From: Janma on
hi... I have written the following code in my BHO's
onDocumentComplete. What i want to do is that after my page gets
loaded i need to submit the form. Since there was no useful reference
on the net i wrote this thing myself.
can anyone cross-verify?? I managed to get to the IPIEHTMLFormElement*
pElement; line successfully. For www.gmail.com. The number of forms
returned was 1. So i got that element. But when I try to
queryinterface the
IPIEHTMLFormElement it fails. Please advice me to get past this line.
Below is my code sample

void __stdcall CBHOObj::OnDocumentComplete(IDispatch * pDisp, VARIANT
* pvtURL)
{
CComPtr<IDispatch> spDispDoc;

// Getting the current webpage from the browser
HRESULT res = m_spWebBrowser2->get_Document(&spDispDoc);

if(SUCCEEDED(res))
{
IPIEHTMLDocument2 *pHTMLDocument;
IPIEHTMLWindow2 *pHTMLWindow;
IPIEHTMLElementCollection *pHTMLElementCollection;
spDispDoc->QueryInterface( __uuidof(IPIEHTMLDocument2),
(void**)&pHTMLDocument);
if (pHTMLDocument)
{
pHTMLDocument->get_forms(&pHTMLElementCollection);
long pHTMLElementCollectionLength = 0;
if (pHTMLElementCollection)
{
pHTMLElementCollection->get_length(&pHTMLElementCollectionLength);
CString abc;
abc.Format(L"%ld",pHTMLElementCollectionLength);
MessageBox (NULL, abc,L"BHO", MB_OK);
for (int i = 0; i < (int)pHTMLElementCollectionLength ; i++)
{
VARIANT vtIndex,vtName;
vtIndex.vt = VT_UINT;
vtIndex.lVal = i;
vtName.vt = VT_UINT;
vtName.lVal = i;

IDispatch* pItem = NULL;

HRESULT hr = pHTMLElementCollection->item(vtName, vtIndex ,
&pItem);
if(SUCCEEDED(hr))
{
IPIEHTMLFormElement* pElement;
hr = pItem->QueryInterface(__uuidof(IPIEHTMLFormElement) , (void
**)&pElement );

if(SUCCEEDED(hr)) //E_NOINTERFACE
{
pElement->submit();
}
}
}
}
}
}
}
From: Saju on
Are you using Mobile 5.0 ? or 2003 ??


"Janma" <rohitku(a)gmail.com>
> hi... I have written the following code in my BHO's
> onDocumentComplete. What i want to do is that after my page gets
> loaded i need to submit the form. Since there was no useful reference
> on the net i wrote this thing myself.
> can anyone cross-verify?? I managed to get to the IPIEHTMLFormElement*
> pElement; line successfully. For www.gmail.com. The number of forms
> returned was 1. So i got that element. But when I try to
> queryinterface the
> IPIEHTMLFormElement it fails. Please advice me to get past this line.
> Below is my code sample
>
> void __stdcall CBHOObj::OnDocumentComplete(IDispatch * pDisp, VARIANT
> * pvtURL)
> {
> CComPtr<IDispatch> spDispDoc;
>
> // Getting the current webpage from the browser
> HRESULT res = m_spWebBrowser2->get_Document(&spDispDoc);
>
> if(SUCCEEDED(res))
> {
> IPIEHTMLDocument2 *pHTMLDocument;
> IPIEHTMLWindow2 *pHTMLWindow;
> IPIEHTMLElementCollection *pHTMLElementCollection;
> spDispDoc->QueryInterface( __uuidof(IPIEHTMLDocument2),
> (void**)&pHTMLDocument);
> if (pHTMLDocument)
> {
> pHTMLDocument->get_forms(&pHTMLElementCollection);
> long pHTMLElementCollectionLength = 0;
> if (pHTMLElementCollection)
> {
> pHTMLElementCollection->get_length(&pHTMLElementCollectionLength);
> CString abc;
> abc.Format(L"%ld",pHTMLElementCollectionLength);
> MessageBox (NULL, abc,L"BHO", MB_OK);
> for (int i = 0; i < (int)pHTMLElementCollectionLength ; i++)
> {
> VARIANT vtIndex,vtName;
> vtIndex.vt = VT_UINT;
> vtIndex.lVal = i;
> vtName.vt = VT_UINT;
> vtName.lVal = i;
>
> IDispatch* pItem = NULL;
>
> HRESULT hr = pHTMLElementCollection->item(vtName, vtIndex ,
> &pItem);
> if(SUCCEEDED(hr))
> {
> IPIEHTMLFormElement* pElement;
> hr = pItem->QueryInterface(__uuidof(IPIEHTMLFormElement) , (void
> **)&pElement );
>
> if(SUCCEEDED(hr)) //E_NOINTERFACE
> {
> pElement->submit();
> }
> }
> }
> }
> }
> }
> }