经过几番搜索,得出结论:
1)服务器是.Net2.0会给cookie加上HttpOnly属性,会使客户端无法通过IE接口读取到cookie.只能读到普通的cookie
2)VS.NET2005与VC6是有区别的,m_pClientSite不同,而且要注意BSTR得到cookie
对于VS.NET2005:
void CActiveXCtrl::OnClick(USHORT iButton)
{
HRESULT hr = S_OK;
IServiceProvider *isp = NULL;
IServiceProvider *isp2 = NULL;
if (!m_pClientSite)
{
return;
}
else
{
hr = m_pClientSite->QueryInterface(IID_IServiceProvider, reinterpret_cast<void **>(&isp));
if (FAILED(hr))
{
hr = S_OK;
ASSERT(FALSE);
return;
}
hr = isp->QueryService(SID_STopLevelBrowser, IID_IServiceProvider, reinterpret_cast<void **>(&isp2));
if (FAILED(hr))
{
hr = S_OK;
ASSERT(FALSE);
return;
}
IWebBrowser2 *browser = NULL;
hr = isp2->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, reinterpret_cast<void **>(&browser));
if (FAILED(hr))
{
hr = S_OK;
ASSERT(FALSE);
return;
}
IDispatch *pDispatch;
if(FAILED(browser->get_Document(&pDispatch))){
hr = S_OK;
ASSERT(FALSE);
return;
}
IHTMLDocument2 *pDocument;
if(FAILED(pDispatch->QueryInterface(IID_IHTMLDocument2, reinterpret_cast<void **>(&pDocument)))){
hr = S_OK;
ASSERT(FALSE);
return;
}
BSTR str1;
BSTR str;
if(S_OK==pDocument->get_cookie(&str)){
CString text(str);
TRACE(text);
MessageBox(text);
//url=text;
}
if(S_OK==pDocument->put_title(str)){
}
if(S_OK==pDocument->get_referrer(&str)){
CString text(str);
TRACE(text);
//url=text;
}
return;
}
}