PROBLEM
1. How do i programmatically scroll an IWebBrowser2 control in all IE versions?
2. Why is it that the code i have runs in IE6 but crashes in IE7?
3. Follow-up to question(2), is there a way to work around the Access Violation in mshtml.dll when calling functions from the IHTMLWindow2, IHTMLElement2, IHTMLDocument2 and IHTMLDocument3? (ex. get_scrollTop, get_scrollHeight, get_ScrollWidth, get_parentWindow)
THANKS!
CODE
Code:
//error trapping had been removed
BOOL CBrowserControl::Scroll(LONG scrollType)
{
CComPtr<IDispatch> spDoc;
long scrollPos;
m_spWebBrowser->get_Document(&spDoc);
IHTMLDocument2 *pDocument = NULL;
HRESULT hresult = spDoc->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
//hresult is S_OK
IHTMLElement *pBody = NULL;
hresult = pDocument->get_body( &pBody );
IHTMLTextContainer *pElement = NULL;
hresult = pBody->QueryInterface(IID_IHTMLTextContainer,(void**)&pE lement);
//hresults are S_OK
IHTMLWindow2 *pWindow = NULL;
hresult = pDocument->get_parentWindow( &pWindow );
//the crash happens here. cannot read hresult anymore since an access violation happens upon calling the function
long scrollwidth, scrollheight;
pElement->get_scrollHeight(&scrollheight);
//a crash here occurs too if i try to comment the code above
pElement->get_scrollWidth(&scrollwidth);
//still crashes here
long page;
m_spWebBrowser->get_Height(&page);
switch(scrollType)
{
case StepDown:
............//other cases here
}
pWindow->scrollBy( 0, scrollPos );
return true;
}