可是编译的时候是通过的。运行的时候会提示说atlbase.h里有错误。
打开看那个文件说
//The assert on operator& usually indicates a bug. If this is really
//what is needed, however, take the address of the p member explicitly.
T** operator&()
{
ATLASSERT(p==NULL);
return &p;
}
请高手解答。
6 个解决方案
#1
应该是你的操作符出了问题
#2
那我不知道如何处理了。请高手解答。
#3
你的p是null,然后你对他取了地址。过不了它的assert
是你的代码里面有问题。
是你的代码里面有问题。
#4
void CGetLinksDlg::OnBnClickedGetlinks()
{
TCHAR HostName[2*MAX_PATH];
CComPtr<IDispatch> spDispatch;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IHTMLElementCollection> pElementCol;
CComPtr<IHTMLAnchorElement> pLoct;
// TODO: Add your control notification handler code here
int n = m_LinksList.GetItemCount();//GetCount();
for (int i = 0; i < n; i ++)
{
IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_LinksList.GetItemData(i);
if (pBrowser)
{
pBrowser->Release();
}
}
m_LinksList.DeleteAllItems();
m_LinksNum = 0;
Log("**************************************************************");
Log("\r\n");
if (m_spSHWinds)
{
int n = m_spSHWinds->GetCount();
for (int i = 0; i < n; i++)
{
_variant_t v = (long)i;
IDispatchPtr spDisp = m_spSHWinds->Item(v);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); //生成一个IE窗口的智能指针
if (spBrowser)
{
if (SUCCEEDED(spBrowser->get_Document( &spDispatch)))
{
pDoc2 = spDispatch;
}
if(pDoc2!=NULL)
{
if (SUCCEEDED(pDoc2->get_links(&pElementCol)))
{
// AfxMessageBox("IHTMLElementCollection");
long p=0;
if(SUCCEEDED(pElementCol->get_length(&p)))
{
if(p!=0)
{
m_LinksNum = m_LinksNum+p;
UpdateData(FALSE);
for(long i=0;i<=(p-1);i++)
{
CComBSTR String;
_variant_t index = i;
//就是这里出错了
if(SUCCEEDED(pElementCol->item(index,index,&spDispatch)))
{
if(SUCCEEDED(spDispatch->QueryInterface( IID_IHTMLAnchorElement,(void **) &pLoct)))
{
//搞不懂
pLoct->get_href(&String);
}
}
ZeroMemory(HostName,2*MAX_PATH);
lstrcpy(HostName,_bstr_t(String));
//添加到列表
m_LinksList.InsertItem(i,HostName);
m_LinksList.SetCheck(i,TRUE);
pLoct->get_hostname(&String);
ZeroMemory(HostName,2*MAX_PATH);
lstrcpy(HostName,_bstr_t(String));
if(lstrlen(HostName))
{
m_LinksList.SetItemText(i,1,HostName);
Log(HostName );
Log("\r\n");
}
}
}
}
}
}
}
}
}
}
{
TCHAR HostName[2*MAX_PATH];
CComPtr<IDispatch> spDispatch;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IHTMLElementCollection> pElementCol;
CComPtr<IHTMLAnchorElement> pLoct;
// TODO: Add your control notification handler code here
int n = m_LinksList.GetItemCount();//GetCount();
for (int i = 0; i < n; i ++)
{
IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_LinksList.GetItemData(i);
if (pBrowser)
{
pBrowser->Release();
}
}
m_LinksList.DeleteAllItems();
m_LinksNum = 0;
Log("**************************************************************");
Log("\r\n");
if (m_spSHWinds)
{
int n = m_spSHWinds->GetCount();
for (int i = 0; i < n; i++)
{
_variant_t v = (long)i;
IDispatchPtr spDisp = m_spSHWinds->Item(v);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); //生成一个IE窗口的智能指针
if (spBrowser)
{
if (SUCCEEDED(spBrowser->get_Document( &spDispatch)))
{
pDoc2 = spDispatch;
}
if(pDoc2!=NULL)
{
if (SUCCEEDED(pDoc2->get_links(&pElementCol)))
{
// AfxMessageBox("IHTMLElementCollection");
long p=0;
if(SUCCEEDED(pElementCol->get_length(&p)))
{
if(p!=0)
{
m_LinksNum = m_LinksNum+p;
UpdateData(FALSE);
for(long i=0;i<=(p-1);i++)
{
CComBSTR String;
_variant_t index = i;
//就是这里出错了
if(SUCCEEDED(pElementCol->item(index,index,&spDispatch)))
{
if(SUCCEEDED(spDispatch->QueryInterface( IID_IHTMLAnchorElement,(void **) &pLoct)))
{
//搞不懂
pLoct->get_href(&String);
}
}
ZeroMemory(HostName,2*MAX_PATH);
lstrcpy(HostName,_bstr_t(String));
//添加到列表
m_LinksList.InsertItem(i,HostName);
m_LinksList.SetCheck(i,TRUE);
pLoct->get_hostname(&String);
ZeroMemory(HostName,2*MAX_PATH);
lstrcpy(HostName,_bstr_t(String));
if(lstrlen(HostName))
{
m_LinksList.SetItemText(i,1,HostName);
Log(HostName );
Log("\r\n");
}
}
}
}
}
}
}
}
}
}
#5
原作者是在vc7 winxp下编译的。现在我用的是vc6 windows2000
#6
up
#1
应该是你的操作符出了问题
#2
那我不知道如何处理了。请高手解答。
#3
你的p是null,然后你对他取了地址。过不了它的assert
是你的代码里面有问题。
是你的代码里面有问题。
#4
void CGetLinksDlg::OnBnClickedGetlinks()
{
TCHAR HostName[2*MAX_PATH];
CComPtr<IDispatch> spDispatch;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IHTMLElementCollection> pElementCol;
CComPtr<IHTMLAnchorElement> pLoct;
// TODO: Add your control notification handler code here
int n = m_LinksList.GetItemCount();//GetCount();
for (int i = 0; i < n; i ++)
{
IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_LinksList.GetItemData(i);
if (pBrowser)
{
pBrowser->Release();
}
}
m_LinksList.DeleteAllItems();
m_LinksNum = 0;
Log("**************************************************************");
Log("\r\n");
if (m_spSHWinds)
{
int n = m_spSHWinds->GetCount();
for (int i = 0; i < n; i++)
{
_variant_t v = (long)i;
IDispatchPtr spDisp = m_spSHWinds->Item(v);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); //生成一个IE窗口的智能指针
if (spBrowser)
{
if (SUCCEEDED(spBrowser->get_Document( &spDispatch)))
{
pDoc2 = spDispatch;
}
if(pDoc2!=NULL)
{
if (SUCCEEDED(pDoc2->get_links(&pElementCol)))
{
// AfxMessageBox("IHTMLElementCollection");
long p=0;
if(SUCCEEDED(pElementCol->get_length(&p)))
{
if(p!=0)
{
m_LinksNum = m_LinksNum+p;
UpdateData(FALSE);
for(long i=0;i<=(p-1);i++)
{
CComBSTR String;
_variant_t index = i;
//就是这里出错了
if(SUCCEEDED(pElementCol->item(index,index,&spDispatch)))
{
if(SUCCEEDED(spDispatch->QueryInterface( IID_IHTMLAnchorElement,(void **) &pLoct)))
{
//搞不懂
pLoct->get_href(&String);
}
}
ZeroMemory(HostName,2*MAX_PATH);
lstrcpy(HostName,_bstr_t(String));
//添加到列表
m_LinksList.InsertItem(i,HostName);
m_LinksList.SetCheck(i,TRUE);
pLoct->get_hostname(&String);
ZeroMemory(HostName,2*MAX_PATH);
lstrcpy(HostName,_bstr_t(String));
if(lstrlen(HostName))
{
m_LinksList.SetItemText(i,1,HostName);
Log(HostName );
Log("\r\n");
}
}
}
}
}
}
}
}
}
}
{
TCHAR HostName[2*MAX_PATH];
CComPtr<IDispatch> spDispatch;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IHTMLElementCollection> pElementCol;
CComPtr<IHTMLAnchorElement> pLoct;
// TODO: Add your control notification handler code here
int n = m_LinksList.GetItemCount();//GetCount();
for (int i = 0; i < n; i ++)
{
IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_LinksList.GetItemData(i);
if (pBrowser)
{
pBrowser->Release();
}
}
m_LinksList.DeleteAllItems();
m_LinksNum = 0;
Log("**************************************************************");
Log("\r\n");
if (m_spSHWinds)
{
int n = m_spSHWinds->GetCount();
for (int i = 0; i < n; i++)
{
_variant_t v = (long)i;
IDispatchPtr spDisp = m_spSHWinds->Item(v);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); //生成一个IE窗口的智能指针
if (spBrowser)
{
if (SUCCEEDED(spBrowser->get_Document( &spDispatch)))
{
pDoc2 = spDispatch;
}
if(pDoc2!=NULL)
{
if (SUCCEEDED(pDoc2->get_links(&pElementCol)))
{
// AfxMessageBox("IHTMLElementCollection");
long p=0;
if(SUCCEEDED(pElementCol->get_length(&p)))
{
if(p!=0)
{
m_LinksNum = m_LinksNum+p;
UpdateData(FALSE);
for(long i=0;i<=(p-1);i++)
{
CComBSTR String;
_variant_t index = i;
//就是这里出错了
if(SUCCEEDED(pElementCol->item(index,index,&spDispatch)))
{
if(SUCCEEDED(spDispatch->QueryInterface( IID_IHTMLAnchorElement,(void **) &pLoct)))
{
//搞不懂
pLoct->get_href(&String);
}
}
ZeroMemory(HostName,2*MAX_PATH);
lstrcpy(HostName,_bstr_t(String));
//添加到列表
m_LinksList.InsertItem(i,HostName);
m_LinksList.SetCheck(i,TRUE);
pLoct->get_hostname(&String);
ZeroMemory(HostName,2*MAX_PATH);
lstrcpy(HostName,_bstr_t(String));
if(lstrlen(HostName))
{
m_LinksList.SetItemText(i,1,HostName);
Log(HostName );
Log("\r\n");
}
}
}
}
}
}
}
}
}
}
#5
原作者是在vc7 winxp下编译的。现在我用的是vc6 windows2000
#6
up