是这样的,我通过ihtmldocument2的fames得到一个IHtmlFramesCollection2接口,然后用IHtmlFramesCollection2接口的item(i)得到其中一个框架IHtmlWindow2接口,再通过IHtmlWindow2的document得到该框架的IHtmlDocument2接口。这个时候就遇到了一个问题,如果框架网页的地址的域与父网页的地址的域不同,就会出现异常“Access is denied”。如http://www.a.com/a.htm和http://www.b.com/b.htm,b是a的框架网页。 但如果两个网页的域相同,比如都在www.a.com下,那就工作正常。
    各位大哥哥点拨一下小弟啊,都急死了。谢谢了!

解决方案 »

  1.   

    IHTMLDocument2 * pDoc = ...;
    IHTMLWindow2 *pHTMLWnd = NULL;
    IHTMLDocument2 * pFrameDoc=NULL;
    IHTMLFramesCollection2 *pFramesCollection=NULL;
    LPDISPATCH lpDispatch; long p;
    VARIANT varindex,varresult;
    varresult.vt=VT_DISPATCH;
    varindex.vt = VT_I4;
    if(pDoc!=NULL)
    {
    HRESULT hr=pDoc->get_frames(&pFramesCollection);
    if(SUCCEEDED(hr)&&pFramesCollection!=NULL)
    {
    hr=pFramesCollection->get_length(&p);
    if(SUCCEEDED(hr))
    for(int i=0; i<p; i++)
    {
    varindex.lVal = i;
    if(pFramesCollection->item(&varindex, &varresult) ==S_OK)
    {
    lpDispatch=(LPDISPATCH)varresult.ppdispVal;
    if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd)))
    {
    if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc)))
    {
    //work with the pFrameDoc...
    }
    pHTMLWnd->Release();
    pHTMLWnd=NULL;
    }
    }
    }
    pFramesCollection->Release();
    }
    pDoc->Release();
    }