此问题与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 retrieved 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 // Callback 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中运行应用程序时,我收到以下错误:
错误代码:INET_E_DOWNLOAD_FAILURE
描述:指定的资源或回调接口无效。
谷歌搜索了几个小时,但仍然没有运气。如果有解决方案,我们将非常感激。
该程序是使用Visual Studio 2015
创建的