Difference between revisions of "URLDownloadToFile"

From wiki.visual-prolog.com

m (categorized)
(simplify)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
For downloading, there is a Windows API called '''URLDownloadToFile''' which can do the job. This API needs '''urlmon.dll''' which is present in all Windows.
For downloading, there is a Windows API called '''URLDownloadToFile''' which can do the job.


In your program, add the lines:  
In your program, add the lines:  


<vip>class predicates
<vip>
  urlDownloadToFile : (unsigned,string URL,string File,unsigned32 Reserved,unsigned Callback) -> unsigned32 Hresult
class predicates
        language apicall as "URLDownloadToFile".
    uRLDownloadToFile : (handle, string URL, string File, unsigned Reserved, unsigned Callback)  
resolve
        -> unsigned Hresult language apicall.
  urlDownloadToFile externally  % This needs urlmon.lib


class predicates
class predicates
     doDownload : (string SourceURL, string Destfile).
     doDownload : (string SourceURL, string Destfile) [used].
clauses
clauses
  doDownload(SourceURL, Destfile) :-
    doDownload(SourceURL, Destfile) :-
         Hresult = uRLDownloadToFile(0,SourceURL,Destfile,0,0),
         Hresult = uRLDownloadToFile(nullHandle, SourceURL, Destfile, 0, 0),
         common_exception::checkNoApiException(classInfo, Hresult, "URLDownloadToFile",
         if winErrors::s_ok <> Hresult then
            [namedValue("SourceURL", string(SourceURL)), namedValue("Destfile", string(Destfile))]).</vip>
            exception::raise_nativeCallException("URLDownloadToFile", Hresult,
 
                [namedValue("SourceURL", string(SourceURL)), namedValue("Destfile", string(Destfile))])
You will alo need to add '''urlmon.lib''' to your project, because '''URLDownloadToFile''' is not in the Visual Prolog libs.
        end if.
 
</vip>
'''urlmon.lib''' is part of the [[wikipedia:Microsoft Windows SDK]].


[[Category:Examples]]
[[Category:Examples]]
[[Category:Internet]]
[[Category:Internet]]
[[Category:Tips and Tricks]]
[[Category:Tips and Tricks]]

Latest revision as of 16:16, 19 February 2019

For downloading, there is a Windows API called URLDownloadToFile which can do the job.

In your program, add the lines:

class predicates
    uRLDownloadToFile : (handle, string URL, string File, unsigned Reserved, unsigned Callback) 
        -> unsigned Hresult language apicall.
 
class predicates
    doDownload : (string SourceURL, string Destfile) [used].
clauses
    doDownload(SourceURL, Destfile) :-
        Hresult = uRLDownloadToFile(nullHandle, SourceURL, Destfile, 0, 0),
        if winErrors::s_ok <> Hresult then
            exception::raise_nativeCallException("URLDownloadToFile", Hresult,
                [namedValue("SourceURL", string(SourceURL)), namedValue("Destfile", string(Destfile))])
        end if.