URLDownloadToFile-某些页面未下载 [英] URLDownloadToFile - some pages is not download

查看:82
本文介绍了URLDownloadToFile-某些页面未下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我使用函数URLDownloadToFile下载HTML页面.
(请参阅urlmon.h)

某些页面下载正常,但有些页面则无法下载.
例如,http://www.microsoft.com,http://www.google.com等...
函数返回错误MK_E_SYNTAX _HRESULT_TYPEDEF_(0x800401E4L)O_O.是什么?
有什么主意吗?
谢谢您的关注.

Hello guys,
I use function URLDownloadToFile to download a HTML page.
(see urlmon.h)

Some pages download fine, but some is not download.
For example, http://www.microsoft.com, http://www.google.com etc...
The function return error MK_E_SYNTAX _HRESULT_TYPEDEF_(0x800401E4L) O_O. What is it?
Any idea?
Thank you for attention.

推荐答案

似乎Win7为我们做了一些工作-也就是说,我只是在装有XP的虚拟机中尝试了代码和VS2005-我遇到了相同的问题,即错误(来自监视窗口)-"hRes 0x800401e4 HRESULT的语法无效"

晚上早些时候,我读到您需要确保为线程初始化了COM.我不理会它,而是继续耕作-当我使用Win7和Vs2010时,这很好.

无论如何,解决方法是使用CoInitialize(NULL);.在调用URLDownloadToFile之前-进行此更改后,hRes之后将保留S_OK. :)

在XP中经过VS2005测试的列表
It seems that Win7 does some of the work for us - that is to say, I just tried the code in a virtual machine with XP and VS2005 - I got the same problem, i.e error (from the watch window) - "hRes 0x800401e4 Invalid syntax HRESULT"

Earlier in the evening I had read that you need to make sure COM is initialized for the thread. I disregarded this and plowed on - this was fine when I used Win7 and Vs2010.

Anyway, the fix was to use CoInitialize(NULL); before the call to URLDownloadToFile - after this change, hRes holds S_OK afterwards. :)

Listing as tested with VS2005 in XP
#include "stdafx.h"
#include <windows.h>
#include <urlmon.h>

int main()
{
	CoInitialize(NULL);
	HRESULT hRes;
	hRes = URLDownloadToFile(NULL, L"http://www.google.com/", L"google.com.file", 0, NULL);

	return 0;
}


这篇关于URLDownloadToFile-某些页面未下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆