关于URLDownloadToFile的用法
刚学MFC,在网上看到有这个函数可以下载文件,尝试着给一个按钮加上了这个OnUpdate函数,可是总是不能成功下载,每次显示出来的都是 "网络连接失败.";
在网上找了很多资料都没看出哪里出错了,大家帮忙看看呢~~
================================
void CSysinfoDlg::OnUpdate()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_VER)->SetWindowText("检查是否有新版本...");
HRESULT ret = URLDownloadToFile(NULL,"http://www.blon.cn/systeminfo/update/version.ini","c:\\version.ini",0,NULL);
if(ret == S_OK) //如果下载成功
{
// 读取Version 段的数据,得到新版本好
int newversion=GetPrivateProfileInt("Version","Version",10,"c:\\version.ini");
if (newversion > 10) //跟当前版本比较,10表示目前版本V1.0 ,根据具体版本自己设置
{
GetDlgItem(IDC_VER)->SetWindowText("有新版提供下载,现在开始更新.");
GetPrivateProfileString("URL","URL",0,"http://www.blon.cn/systeminfo/systeminfo.exe ",100,"c:\\version.ini");
ShellExecute(this->m_hWnd,"open","http://www.blon.cn/systeminfo/systeminfo.exe ",NULL,"c:\\",SW_SHOW);
}
else
GetDlgItem(IDC_VER)->SetWindowText("Sorry, There is no new version for this program.");
DeleteFile("c:\\version.ini"); // 用完后删除
}
if(E_OUTOFMEMORY)
GetDlgItem(IDC_VER)->SetWindowText("网络连接失败.");
else
GetDlgItem(IDC_VER)->SetWindowText("无法更新软件");
}