Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accessing frames in a BHO using DOM

7 views
Skip to first unread message

Aniket

unread,
Mar 21, 2005, 8:01:02 AM3/21/05
to
I attempt to access all frames, forms, elements, etc. in a Browser Helper
Object(BHO) for Internet Explorer. After the DISPID_DOCUMENTCOMPLETE event
for the TOP frame (when the IUnknown pointer matches for the IWebBrowser2
with the IDispatch argument to DISPID_DOCUMENTCOMPLETE), when processing the
frames on some sites, I get an "0x80070005 (E_ACCESSDENIED)" for get_document
(I have provided the code below)

I want to know:
(a) under what circumstances does one get the Access Denied error and how
does one prevent it?
(b) if there exists a better way to walk through the form elements using the
DOM? If yes, kindly enligthen me.

HRESULT GetHTMLContent (IHTMLDocument2 *spHTML)
{
HRESULT hr;

CComPtr<IHTMLElementCollection> pForms; // Process the
forms
hr = spHTML->get_forms(&pForms);
if (FAILED(hr))
return hr;
ProcessForms (pForms);

CComPtr<IHTMLFramesCollection2> pFrames; // Process the Frames
hr = spHTML->get_frames(&pFrames);
if (FAILED(hr))
return hr;
ProcessFrames (pFrames);
return S_OK;
}


HRESULT ProcessFrames (IHTMLFramesCollection2 *pCollect)
{
HRESULT hr;
long l;
VARIANT v1, v2;

hr = pCollect->get_length (&l);
if (FAILED (hr))
return hr;

for (int i = 0; i < l; i++) {
// "-------Processing Frame %d out of %d
--------------- ", i+1, l
v1.vt = VT_I4; v1.lVal = i;
VariantClear (&v2);
hr = pCollect->item (&v1, &v2);
if (FAILED(hr))
return hr;
if (v2.vt == VT_DISPATCH) {
CComPtr<IDispatch> pDispatch;
pDispatch = v2.pdispVal;
CComQIPtr<IHTMLWindow2, &IID_IHTMLWindow2> pFrame;
pFrame = pDispatch;
if (pFrame) {
CComPtr<IHTMLDocument2> spHTML;
hr = pFrame->get_document (&spHTML);
if (FAILED(hr)) {
// This is the place where it FAILS
return hr;
}
GetHTMLContent (spHTML);
}
}
}
return S_OK;
}

Jean-Fabrice RABAUTE

unread,
Mar 25, 2005, 11:38:08 AM3/25/05
to Aniket

Hi,

The Microsoft KB 196340 article shoudl answer your problem :

http://support.microsoft.com/kb/196340/en-us

Hope this helps.

--
Regards / Cordialement

====================
Jean-Fabrice Rabaute
CORE SERVICES :: Software/Web development & Consulting services

http://www.debugbar.com : The most advanced WEB development tool for
Internet Explorer
http://www.core-services.fr - {Enjoy the future today}

Jean-Fabrice RABAUTE

unread,
Mar 25, 2005, 11:38:44 AM3/25/05
to Aniket

Hi,

Jean-Fabrice RABAUTE

unread,
Mar 25, 2005, 11:39:08 AM3/25/05
to

Hi,

0 new messages