-
Feb 3rd, 2023, 08:54 PM
#1
Thread Starter
Hyperactive Member
<CONTROL> could not be loaded from MYOCX.ocx (error 372)
I am using a usercontrol ocx to download stuff.
It works fine, but sometimes (randomly?) I get the error "The control 'ucDownload' could not be loaded from tDownload7.ocx" Your version of tDownload7.ocx may be outdated. Please make sure you are using the version of the control that came with your application. Error: 372
Does anybody know why this may be happening?
I have attached code below.
Thank you!
Code:
''#####################################################''
''## ##''
''## Created By BelgiumBoy_007 ##''
''## ##''
''## Visit BartNet @ www.bartnet.be for more Codes ##''
''## ##''
''## Copyright 2004 BartNet Corp. ##''
''## ##''
''#####################################################''
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long
Public Event DownloadErrors(ByVal uErrDescription As String)
Public Event DownloadEvents(ByVal uEvent As String)
Public Event DownloadComplete()
Public Event DownloadProgress(ByVal uMaxBytes As Long, ByVal uCurBytes As Long)
Private m_lFileLen&
Private CancelSearch As Boolean
'Const CHUNK_SIZE As Long = 1024 * 20
Const ROLLBACK As Long = 4096
Private Sub UserControl_Resize()
Width = 32 * Screen.TwipsPerPixelX
Height = 32 * Screen.TwipsPerPixelY
End Sub
Public Sub Cancel()
CancelSearch = True
End Sub
Public Function DownloadFile(strURL As String, strDestination As String, Optional UserName As String = Empty, Optional Password As String = Empty, Optional ByVal uChunkSize As Long = 0) As Boolean
If uChunkSize = 0 Then
uChunkSize = 1024 * 10
End If
Dim bData() As Byte
Dim blnResume As Boolean
Dim intFile%
Dim lngBytesReceived&
Dim lngFileLength&
Dim strFile As String
Dim strHeader As String
Dim strHost As String
On Local Error GoTo InternetErrorHandler
CancelSearch = False
strFile = ReturnFileOrFolder(strDestination, True)
strHost = ReturnFileOrFolder(strURL, True, True)
StartDownload:
If blnResume Then
RaiseEvent DownloadEvents("Resuming download")
lngBytesReceived = lngBytesReceived - ROLLBACK
If lngBytesReceived < 0 Then
lngBytesReceived = 0
End If
Else
RaiseEvent DownloadEvents("Getting file information")
End If
DoEvents
With Inet
.URL = strURL
.UserName = UserName
.Password = Password
.Execute , "GET", , "Range: bytes=" & CStr(lngBytesReceived) & "-" & vbCrLf
While .StillExecuting
DoEvents
If CancelSearch = True Then GoTo ExitDownload
Wend
strHeader = .GetHeader
End With
Select Case Mid(strHeader, 10, 3)
Case "200"
If blnResume Then
Kill strDestination
RaiseEvent DownloadErrors("The server is unable to resume this download.")
CancelSearch = True
GoTo ExitDownload
End If
Case "206"
Debug.Assert falese
Case "204"
RaiseEvent DownloadErrors("Nothing to download!")
CancelSearch = True
GoTo ExitDownload
Case "401"
RaiseEvent DownloadErrors("Authorization failed!")
CancelSearch = True
GoTo ExitDownload
Case "404"
RaiseEvent DownloadErrors("The file, " & """" & Inet.URL & """" & " was not found!")
CancelSearch = True
GoTo ExitDownload
Case vbCrLf
RaiseEvent DownloadErrors("Cannot establish connection.")
CancelSearch = True
GoTo ExitDownload
Case Else
strHeader = Left(strHeader, InStr(strHeader, vbCr))
If strHeader = Empty Then strHeader = "<nothing>"
RaiseEvent DownloadErrors("The server returned the following response:" & vbCr & vbCr & strHeader)
CancelSearch = True
GoTo ExitDownload
End Select
If blnResume = False Then
strHeader = Inet.GetHeader("Content-Length")
lngFileLength = Val(strHeader)
m_lFileLen = lngFileLength
If lngFileLength = 0 Then
GoTo ExitDownload
End If
End If
If Mid(strDestination, 2, 2) = ":\" Then
If DiskFreeSpace(Left(strDestination, InStr(strDestination, "\"))) < lngFileLength Then
RaiseEvent DownloadErrors("There is not enough free space on disk for this file.")
GoTo ExitDownload
End If
End If
DoEvents
If blnResume = False Then lngBytesReceived = 0
On Local Error GoTo FileErrorHandler
strHeader = ReturnFileOrFolder(strDestination, False)
If Dir(strHeader, vbDirectory) = Empty Then
MkDir strHeader
End If
intFile = FreeFile()
Open strDestination For Binary Access Write As #intFile
If blnResume Then Seek #intFile, lngBytesReceived + 1
Do
bData = Inet.GetChunk(uChunkSize, icByteArray)
Put #intFile, , bData
If CancelSearch Then Exit Do
lngBytesReceived = lngBytesReceived + UBound(bData, 1) + 1
RaiseEvent DownloadProgress(m_lFileLen, lngBytesReceived)
DoEvents
Loop While UBound(bData, 1) > 0
Close #intFile
ExitDownload:
If lngBytesReceived = lngFileLength Then
If CancelSearch = False Then RaiseEvent DownloadComplete
DownloadFile = True
Else
If Dir(strDestination) = Empty Then
CancelSearch = True
Else
If CancelSearch = False Then
RaiseEvent DownloadErrors("The connection with the server was reset.")
End If
End If
If Not Dir(strDestination) = Empty Then Kill strDestination
DownloadFile = False
End If
CleanUp:
Inet.Cancel
Exit Function
InternetErrorHandler:
If Err.Number = 9 Then Resume Next
RaiseEvent DownloadErrors("Error: " & Err.Description & " occurred.")
Err.Clear
GoTo ExitDownload
FileErrorHandler:
RaiseEvent DownloadErrors("Cannot write file to disk." & vbCr & vbCr & "Error " & Err.Number & ": " & Err.Description)
CancelSearch = True
Err.Clear
GoTo ExitDownload
End Function
Private Function ReturnFileOrFolder(FullPath As String, ReturnFile As Boolean, Optional IsURL As Boolean = False) As String
Dim intDelimiterIndex As Integer
intDelimiterIndex = InStrRev(FullPath, IIf(IsURL, "/", "\"))
If intDelimiterIndex = 0 Then
ReturnFileOrFolder = FullPath
Else
ReturnFileOrFolder = IIf(ReturnFile, Right(FullPath, Len(FullPath) - intDelimiterIndex), Left(FullPath, intDelimiterIndex))
End If
End Function
Private Function DiskFreeSpace(strDrive As String) As Double
Dim SectorsPerCluster As Long
Dim BytesPerSector As Long
Dim NumberOfFreeClusters As Long
Dim TotalNumberOfClusters As Long
Dim FreeBytes As Long
Dim spaceInt As Integer
strDrive = QualifyPath(strDrive)
GetDiskFreeSpace strDrive, SectorsPerCluster, BytesPerSector, NumberOFreeClusters, TotalNumberOfClusters
DiskFreeSpace = NumberOFreeClusters * SectorsPerCluster * BytesPerSector
End Function
Private Function QualifyPath(strPath As String) As String
QualifyPath = IIf(Right(strPath, 1) = "\", strPath, strPath & "\")
End Function
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|