void CUpDateDlg::OnCheck() 
{
SetDlgItemText(IDC_VER,"正在检查,请等待.......");
int ret=URLDownloadToFil(NULL,"http://146.190.100.13/download/vesion.ini","c:version.ini",0,NULL);
if (ret==0) //如果下载成功
{int newversion=GetPrivateProfileInt("Version","Version",10,"c:version.ini");
if (newversion>10)//跟当前版本比较,10表示目前版本V1.0 
{
SetDlgItemText(IDC_VER,"有新版本了!");// 得到新版本下载地址给变量new_urlGetPrivateProfileString("URL","URL",0,new_url,100,"c:version.ini"); 
}
else
SetDlgItemText(IDC_VER,"抱歉。还没有新版本!");
DeleteFile("c:version.ini"); //用完后删除
}
else
SetDlgItemText(IDC_VER,"网络连接失败");
}
version.ini的定义:
[Version] Version=12
[URL] URL=http://146.190.130.13/download/1.exe
断点调试时,newversion的返回指始终是10。为什么呢?请高手看看。

解决方案 »

  1.   

    GetPrivateProfileInt
    The GetPrivateProfileInt function retrieves an integer associated with a key in the specified section of an initialization file. Note  This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry. 
      

  2.   

    我的测试代码:
    TCHAR new_url[101];
    TCHAR Version[10];
    TCHAR filename[MAX_PATH];
    SetDlgItemText(IDC_VER,"正在检查,请等待.......");
    /*  int ret=URLDownloadToFile(NULL,"http://146.190.100.13/download/vesion.ini","c:\\version.ini",0,NULL);
    */
    GetModuleFileName(NULL,filename,MAX_PATH);
    (_tcsrchr(filename,'\\'))[1] = 0;
    lstrcat(filename,"version.ini"); int ret =0;
    //CString strFileName("c:\\version.ini");
    if (ret==0) //如果下载成功
    {
    //WritePrivateProfileString("Version","Version","12",filename);
    int newversion = GetPrivateProfileInt("Version","Version",10,filename); if (newversion>10)//跟当前版本比较,10表示目前版本V1.0 
    {
    SetDlgItemText(IDC_VER,"有新版本了!");// 得到新版本下载地址给变量new_url

    GetPrivateProfileString("URL","URL",0,new_url,100,filename); 
    }
    else
    {
    SetDlgItemText(IDC_VER,"抱歉。还没有新版本!");
    }
    DeleteFile(filename); //用完后删除
    }
    else
    {
    SetDlgItemText(IDC_VER,"网络连接失败");
    }