2020年2月25日 星期二

URLDownloadToFile - some pages is not download

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
Hide   Copy Code
#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;
}

Posted 12-Aug-12 9:03am
enhzflep


https://www.codeproject.com/Questions/439137/URLDownloadToFile-some-pages-is-not-download

沒有留言:

張貼留言