请教IHTMLLinkElement接口传递的问题
在下学习CExplorer期间,想试着获取一个网页上的所有链接,并获得链接的相应属性,比如地址,名称之类,于是写了这样一个代码:
CComQIPtr<IHTMLDocument2> spDoc = m_Web.get_Document(); if (NULL == spDoc) { return; } HRESULT hRes; long nFormCount = 0; CComBSTR bstrTitle; CString BSLink; CComQIPtr<IHTMLElementCollection> spElementCollection; //取得文档标题 spDoc->get_title(&bstrTitle); //取得超链接集合 hRes = spDoc->get_links(&spElementCollection); if (FAILED(hRes)) { return; } //取得超链接数量 spElementCollection->get_length(&nFormCount); if (FAILED(hRes)) { return; } for (long i = 0; i < nFormCount; ++ i) { IDispatch *pDisp = NULL; //取得第 i 项 hRes = spElementCollection->item(CComVariant(i), CComVariant(), &pDisp); if (FAILED(hRes)) { continue; } //为什么这里指针传递不过来? CComQIPtr<IHTMLLinkElement> spLinkElement = pDisp; }CComPtr<IHTMLLinkElement> spLinkElement;pDisp->QueryInterface(__uuidof(IHTMLLinkElement), (void**)&spLinkElement);