IE获取cookie设置

void Test()
{
if (SUCCEEDED(OleInitialize(NULL)))
{
IWebBrowser2*    pBrowser2;


CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
IID_IWebBrowser2, (void**)&pBrowser2);
if (pBrowser2)
{
VARIANT vEmpty;
VariantInit(&vEmpty);


BSTR bstrURL = SysAllocString(L"http://baidu.com");
//BSTR bstrURL = SysAllocString(L"http://192.168.100.110");


HRESULT hr = pBrowser2->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);


IDispatch* lpDispatch;


// lpWebBrowser2->get_HWND();


hr = pBrowser2->get_Document(&lpDispatch);


if ( hr == S_OK )
{
IHTMLDocument2* lpDocument2;


hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2);
if ( hr == S_OK )
{
BSTR bstrCookie;


hr = lpDocument2->get_cookie(&bstrCookie);
if ( hr == S_OK )
{
char* lpszText2 = _com_util::ConvertBSTRToString(bstrCookie);
MessageBox(NULL, lpszText2, NULL, 0);
SysFreeString(bstrCookie);
}


lpDocument2->Release();
}


lpDispatch->Release();
}
if (SUCCEEDED(hr))
{
pBrowser2->put_Visible(VARIANT_TRUE);
}
else
{
pBrowser2->Quit();
}


SysFreeString(bstrURL);
pBrowser2->Release();
}


OleUninitialize();
}


}

你可能感兴趣的:(IE获取cookie设置)