Consle Start Web

来源:互联网 发布:linux 密码修改无限 编辑:程序博客网 时间:2024/05/13 09:33


#include <windows.h>
#include <exdisp.h>
#include <atlbase.h>
int LoginWebByIE(LPCSTR,LPCSTR,LPCSTR);
void main()
{
 CoInitialize(0);
 CComVariant vUrl("http://ucdo.banzhu.com/");
 char postData[72]="uasm&password=112101jiefei";
 LoginWebByIE("http://ucdo.banzhu.com/","Content-Type:application/x-www-form-urlencoded\r\n",postData);
 CoUninitialize();

}
int LoginWebByIE(LPCSTR szUrl,LPCSTR szHeaders,LPCSTR szPostData)
{
 HRESULT hr;
 CComQIPtr<IDispatch> pWebBrowser;
 pWebBrowser.CoCreateInstance(CLSID_InternetExplorer);//point into instance;

 CComBSTR bstrURL(szUrl);

 CComVariant vHeaders;
 vHeaders.vt=VT_BSTR;
 vHeaders.bstrVal=SysAllocString(L"Content_Type:application/x-www-form-urlencoded\r\n");/*SysAllocString(CComBSTR(szHeaders).Detach())*/

 CComVariant vFlags;
 vFlags.vt=VT_I4;
 vFlags.lVal=navNoReadFromCache | navNoWriteToCache;

 CComVariant vTargetFrameName;
 vTargetFrameName.vt=VT_BSTR;
 vTargetFrameName.bstrVal=SysAllocString(L"_SELF");

 int size=WideCharToMultiByte(CP_ACP,0,(LPCWSTR)szPostData,-1,0,0,0,0);
 char* pPostData=new char[size+1];
 WideCharToMultiByte(CP_ACP,0,(LPCWSTR)szPostData,-1,pPostData,size,0,0);
 SAFEARRAY FAR* sfPost=NULL;
 SAFEARRAYBOUND bound;
 bound.cElements=(ULONG)(strlen(pPostData));
 bound.lLbound=0;
 sfPost=SafeArrayCreate(VT_UI1,1,&bound);
 char* pChar=pPostData;
 for(long lindex=0; lindex<(signed)bound.cElements; lindex++)
 {
     SafeArrayPutElement(sfPost,&lindex,(void*)((pChar++)));
 }
 CComVariant vPostData;
 vPostData.vt=VT_ARRAY | VT_UI1;
 vPostData.parray=sfPost;
 delete[]pPostData;
 pPostData=NULL;
 pChar=NULL;

 CComQIPtr<IWebBrowser2> spBrowse2=pWebBrowser;
 hr=spBrowse2->Navigate(bstrURL,&vFlags,&vTargetFrameName,&vPostData,&vHeaders);
 pWebBrowser.Release();

 return 0;

}

原创粉丝点击