无法使用Visual C ++中的URLDownloadToFile下载文件

这个问题是关于URLDownloadToFile API的使用。

我在Visual C ++ MFC应用程序中使用URLDownloadToFile 。 在Windows Server 2008中,该程序工作正常。

示例代码:

 // invalidate cache, so file is always downloaded from web site // (if not called, the file will be retieved from the cache if // it's already been downloaded.) DeleteUrlCacheEntry(aCSVDownloadURL); CallbackHandler callbackHandler; IBindStatusCallback* pBindStatusCallback = NULL; callbackHandler.QueryInterface(IID_IBindStatusCallback, reinterpret_cast<void**>(&pBindStatusCallback)); HRESULT hr = URLDownloadToFile( NULL, // A pointer to the controlling IUnknown interface DownloadURL, FileName, // Filename to save the downloaded file in local 0, // Reserved. Must be set to 0. pBindStatusCallback // Calback interface to catch the download response; basically the file name ); if (hr == S_OK) { cout << "Download OK" << endl; } else if (hr == E_OUTOFMEMORY) { cout << "The buffer length is invalid, or there is insufficient memory to complete the operation." << endl; } else if (hr == INET_E_DOWNLOAD_FAILURE) { cout << "The specified resource or callback interface was invalid." << endl; } else { cout << "Other error" << endl; } 

但是,在Windows Server 2012 R2中运行应用程序时,请获取以下错误:

 Error code: INET_E_DOWNLOAD_FAILURE Description: The specified resource or callback interface was invalid. 

已经做了几个小时的search,但仍然没有运气。 如果有解决scheme,将非常感激。

该程序是使用Visual Studio 2015创build的