int__fastcall Xsetproxy (void){ //TODO: Set up a proxy server. //return error code://0: Do not use proxy-1:Tinifile *readini =NewTinifile (Getapppath () +ansistring (G_config_ini)); BOOLBuseproxy = Readini->readbool ("FormSet","UseProxy",false); Ansistring Proxysvr= Readini->readstring ("FormSet","Proxysvr",""); Ansistring ProxyPort= Readini->readinteger ("FormSet","ProxyPort",0); Ansistring UserName= Readini->readstring ("FormSet","Proxyuser",""); Ansistring UserPassword= Readini->readstring ("FormSet","PROXYPSW",""); DeleteReadini; Readini=NULL; Ansistring strproxy,temp; if(Proxysvr.pos ("/ http") >0) {Proxysvr= Proxysvr.substring (8, Proxysvr.length ()); } Else if(Proxysvr.pos ("https://") >0) {Proxysvr= Proxysvr.substring (9, Proxysvr.length ()); } temp.sprintf ("%s:%s", Proxysvr,proxyport); strproxy.sprintf ("http=http://%s;ftp=http://%s;https=https://%s", temp,temp,temp); //Get current settingInternet_proxy_info IPI; DWORD DwSize2=sizeof(IPI); //set to not use the proxy first. Ipi.dwaccesstype =Internet_open_type_direct; InternetSetOption (NULL, Internet_option_proxy,&IPI, dwSize2); InternetSetOption (NULL, Internet_option_refresh, NULL, NULL); InternetSetOption (NULL, internet_option_settings_changed, NULL,0); if(!buseproxy)returnError_noerror; Ipi.dwaccesstype=Internet_open_type_proxy; Ipi.lpszproxy=Strproxy.c_str (); Ipi.lpszproxybypass="<local>"; if(! InternetSetOption (NULL, Internet_option_proxy, &IPI, DwSize2)) { //MessageBox (Application->handle, "Set proxy fail.", "Setproxyfail", mb_ok| Mb_iconerror); returnError_setproxy; } //set user name and password below//WINAPI does not support SOCK5. //if (username!= "" && userpassword!= "")// {//Char pproxyinfo[200]={0};//lstrcpy (Pproxyinfo,username.c_str ());//if (! InternetSetOption (NULL, Internet_option_proxy_username,//(LPVOID) Pproxyinfo, Lstrlen (pproxyinfo)))// {//return error_setuser;// }////memset (pproxyinfo,0x00,200);//lstrcpy (Pproxyinfo,userpassword.c_str ());//if (! InternetSetOption (NULL, Internet_option_proxy_password,//(LPVOID) Pproxyinfo, Lstrlen (pproxyinfo)))//return ERROR_SETPSW;// } returnError_noerror;}
Use your own proxy server for this program