Ahhh! I see what you are saying... it's interesting because I guess I 'used up' all my sessions but there must be a ton of sessions given to a program because I went through like 2000 downloads before it happened! Are hSessions allocated per program instance... because if you started another instance of my download prog it would work.
I have posted my new code below, tell me how it looks/if you would change anything. I noticed this code floating around this message board and that's how I got it but I guess it's wrong so hopefully this will help some other people out too :-).
VB Code:
Public mySession As Long Public Function openInternetSession() ' This function opens the internet session when the program starts (instead of everytime) ' remember to close the session or you will get runaways! Dim hSession As Long hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0) If Err.LastDllError <> 0 Then MsgBox "Download Module: GetURLSource, error opening internet session" & vbCrLf & vbCrLf & "Error:" & vbCrLf & GetLastError End If If hSession Then mySession = hSession ' now we will use the global variable 'mySession' to access this internet session Else MsgBox "Error: Couldn't open internet session!" End If End Function Public Function closeInternetSession() ' Close the internet session Dim iResult As Integer iResult = InternetCloseHandle(mySession) End Function Public Function GetURLSource(sURL As String) On Error GoTo ErrorHandler Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String Dim hInternet As Long, lReturn As Long hInternet = InternetOpenUrl(mySession, sURL, vbNullString, 0, IF_NO_CACHE_WRITE, 0) If hInternet Then iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn) sData = sBuffer Do While lReturn <> 0 iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn) sData = sData + Mid(sBuffer, 1, lReturn) Loop End If iResult = InternetCloseHandle(hInternet) GetURLSource = sData Exit Function ErrorHandler: MsgBox "Sub/Function: GetURLSource" & vbCrLf & vbCrLf & "Encountered error #" & Err.Number & vbCrLf & Err.Description Resume Next End Function
That look about right?![]()
Thanks a lot franz!




Reply With Quote