Re: URLDownloadToCacheFile
Hi, I'm like to use this API. Can you post a simple code example showing how to use it? Thanks.
VBAhack
Re: URLDownloadToCacheFile
Hope this will help:
VB Code:
Private Declare Function URLDownloadToCacheFile Lib "urlmon" Alias "URLDownloadToCacheFileA" ( _
ByVal lpUnkcaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwBufLength As Long, _
ByVal dwReserved As Long, _
ByVal IBindStatusCallback As Long) As Long
Private Const E_FAIL As Long = &H80004005
Private Const E_OUTOFMEMORY As Long = &H8007000E
Private Const S_OK As Long = &H0
Private Const MAX_PATH As Long = 260
Private Function DownloadPic(myUrl As String) As String
Dim retValue As Long
Dim localFileName As String
On Error GoTo trackError
'prepare the variable that will be filled with the name that the file, once
'downloaded, receives.
localFileName = Space$(MAX_PATH)
'if the url was already downloaded into the cache and exists there, it
'is not downloaded again. Instead, localFileName receives the name of the file that
'is already in the Cache
retValue = URLDownloadToCacheFile(0, myUrl, localFileName, Len(localFileName), 0, 0)
If retValue = S_OK Then
DownloadPic = Left$(localFileName, InStr(localFileName, vbNullChar) - 1)
Else
DownloadPic = vbNullString
End If
Exit Function
trackError:
DownloadPic = vbNullString
End Function
Re: URLDownloadToCacheFile
Thanks very much. Tried it and it works, but I was under the mistaken impression that the cache was RAM, not disk. Thus, the only difference between URLDownloadToFile and URLDownloadToCacheFile is that with the former, you need to specify the name/path where you want the file saved. Thanks for helping to make the differences clear.
VBAhack