int Glip(string &Inernet_ip)
{
Inernet_ip.resize(32);
TCHAR szTempPath[_MAX_PATH] = {0}, szTempFile[MAX_PATH] = {0};
string buffer;
GetTempPath(MAX_PATH, szTempPath);
UINT nResult = GetTempFileName(szTempPath, _T("~ex"), 0, szTempFile);
int ret=URLDownloadToFile(NULL,_T("http://www.ip138.com/ip2city.asp"),_T(szTempFile),BINDF_GETNEWESTVERSION,NULL);
if (ret == S_FALSE)
{
return 0;
}
FILE *fp;
if ((fp = fopen(szTempFile, "rb")) == NULL)
{
return 0;
}
fseek(fp,0,SEEK_END);//得到文件大小
int ilength=ftell(fp);
fseek(fp,0,SEEK_SET);
if(ilength>0)
{
buffer.resize(ilength);
fread(&buffer[0],sizeof(TCHAR),ilength,fp);
fclose(fp);
DeleteFile(_T("ip.ini"));
char* str_ip = strstr(&buffer[0], "[");
if (str_ip !=NULL)
{
sscanf(str_ip+1, "%[^]]", &Inernet_ip[0]);
}
return 1;
}
else
{
fclose(fp);
return 0;
}
}
缺少 include 吧,这个是 inet.dll 库的
#pragma comment(lib, "Urlmon.lib")