- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 c++ 的新手,尝试编写一个更新函数。
使用 URLDownloadToFile 下载没有问题,但如果我将 url 更改为无效的 url,它仍然返回 S_OK ...如何检查下载是否成功?
#include <WinInet.h>
#include <iomanip>
int download_file (const TCHAR urldownload[],const TCHAR target[] )
{
DownloadProgress progress;
IBindStatusCallback* callback = (IBindStatusCallback*)&progress;
SCP(40, NULL); cout << target;
HRESULT status = URLDownloadToFile(NULL, urldownload, target, 0, static_cast<IBindStatusCallback*>(&progress));
Sleep(200);
DeleteUrlCacheEntry(urldownload);
wcout << status;
if (status == S_OK) cout << "yes";
else(cout << "Download failed");
Sleep(10000); return 1;
}
class DownloadProgress : public IBindStatusCallback {
public:
HRESULT __stdcall QueryInterface(const IID &, void **) {
return E_NOINTERFACE;
}
ULONG STDMETHODCALLTYPE AddRef(void) {
return 1;
}
ULONG STDMETHODCALLTYPE Release(void) {
return 1;
}
HRESULT STDMETHODCALLTYPE OnStartBinding(DWORD dwReserved, IBinding *pib) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetPriority(LONG *pnPriority) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE OnLowResource(DWORD reserved) {
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE OnStopBinding(HRESULT hresult, LPCWSTR szError) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetBindInfo(DWORD *grfBINDF, BINDINFO *pbindinfo) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed) {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable(REFIID riid, IUnknown *punk) {
return E_NOTIMPL;
}
virtual HRESULT __stdcall OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
{
//wcout << ulProgress << L" of " << ulProgressMax << endl; Sleep(200);
if (ulProgress != 0 && ulProgressMax != 0)
{
double output = (double(ulProgress) / ulProgressMax)*100;
cout << "\r" << "Downloading: " << fixed << setprecision(2) << output << " % " ; Sleep(20);
}
return S_OK;
}
};
最佳答案
MSDN article has the answer给你:
URLDownloadToFile
returnsS_OK
even if the file cannot be created and the download is canceled. If the szFileName parameter contains a file path, ensure that the destination directory exists before callingURLDownloadToFile
. For best control over the download and its progress, anIBindStatusCallback
interface is recommended.
您需要提供一个状态回调来接收异步操作的状态。您的代码片段已经有了基础。 OnProgress
和 OnStopBinding
应该让您得到下载失败的结果。
关于c++ - URLDownloadToFile 总是返回 S_OK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32288137/
我是 c++ 的新手,尝试编写一个更新函数。 使用 URLDownloadToFile 下载没有问题,但如果我将 url 更改为无效的 url,它仍然返回 S_OK ...如何检查下载是否成功? #i
场景如下: 我有 WSCF Blue 生成的 C# Web 服务客户端,我必须从 C 调用它。我使用 C++ CLI“桥”来完成它。在 C# web 服务客户端我有 namespace MyCompa
在我正在处理的遗留 C++ 代码中,我注意到许多返回 HRESULT 的方法遵循将局部变量设置为 S_OK 的做法,然后在方法末尾返回它而不更改它。 HRESULT function()
如何比较方法返回的值与 HRESULT?我试过了,但它不起作用: FPropStg.DeleteMultiple(1, psProp) == VSConstants.S_OK DeleteMultip
我正在编写一个远程连接到服务器的客户端应用程序。我需要模拟我的客户将与之合作的用户。 这是我的代码的摘录: COAUTHIDENTITY coAuthIdentity, *pCoAuthIdentit
所以我有以下代码: extern ID3D11Device* dev; extern ID3D11DeviceContext* devcon; //shaders
前段时间,我不得不修改一个旧的 COM DLL(Visual C++ 2010,ATL),将它从“Apartment”线程模型迁移到“Both”,即现在可以从 STA 和 MTA 线程调用它而无需序列
我在 Windows 7 中遇到了这个问题。首先我定义了一个实现 IDropTarget 的类。然后,我将 RegisterDragDrop 与放置在我的应用程序窗口中的控件的句柄一起使用。 Regi
我正在使用最新的 Flash 播放器,并从我的开发机器本地提供一个 swf 文件。在一个容器测试应用程序中,我能够播放 swf 并调用它,但在我的“真实”应用程序中,相同的代码路径会导致 com 错误
我正在实现一个 COM 接口(interface),它应该返回 S_OK 或 E_FAIL 的 int 值。我可以返回 S_OK,因为我从另一个调用 (Marshal.QueryInterface)
我目前正在对广泛使用 COM/MFC/(谁知道还有多少其他技术)的项目进行升级。作为升级的一部分,我们正尝试将尽可能多的功能移动到托管 C# 代码中,但不幸的是,有些东西无法移动(出于我不会讨论的原因
我正在用 3D 模型做一个项目,这很重要。所以,我使用的是 SAPI 5.1,我想在有 Viseme 事件时异步调用一个函数(以便播放与之相关的动画)。 我该怎么做? 非常感谢。 注意:我使用:hRe
我是一名优秀的程序员,十分优秀!