c++urlmon

Waiting for URLDownloadToFile() to end


I want to make the program that downloads page from internet and makes some parsing on it. Second part is easy, problem is first.

I want to use URLDownloadToFile() function. But by default it doesn't wait for completing the download. MSDN says that the last param is sort of callback function, but I can't find any info of how to use it (when it is called and what it must do, even what type of function it is). Can someone explain me what is that last parameter and how use it (in C++) to make my app wait?


Solution

  • Something as simple as the sample below should do the trick if you want to just download the file synchronously:

    HRESULT hRez = URLDownloadToFile( NULL, _T(<url>), _T(<file>), 0, NULL );
    if( hRez == 0 ){
     // download ok
    }
    else{
     // download failed
    }