Интересно было б реализовать функционал закачки файлов в приложении. Для этого я решил использовать
URLDownloadToFile из urlmon.dll. Она почему то не отрабатывает. Для теста в этом же коде использовал и фунуцию
OpenInternet. С интом вроде как коннектится, но файлы качать не хочет.
n.b. никаких предварительных настроек не делал . Пишу на VB 2008
вначале у меня
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const scUserAgent = "VB Project"
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hOpen As Long, ByVal sUrl As String, ByVal sHeaders As String, ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, ByVal lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
ЗАТЕМ
Private Sub OpenURL(ByVal sUrl As String)
Dim hOpen As Long
Dim hOpenUrl As Long
Dim bDoLoop As Boolean
'Dim sReadBuffer(2048) As String
' Dim sBuffer As String
Dim DownLoadFile As Boolean
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
bDoLoop = True
If URLDownloadToFile(0, "http://***/14155_5000-150x0.jpg", "c:\image.jpg", 0, 0) = 0 Then
DownLoadFile = True
Else
DownLoadFile = False
End If
MsgBox(DownLoadFile)
If hOpenUrl <> 0 Then
InternetCloseHandle(hOpenUrl)
End If
If hOpen <> 0 Then
InternetCloseHandle(hOpen)
End If
End Sub
Подскажите пожалуйста в чем же может быть дело?...