參考看看
語法:
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
hpvDest As Any, _
ByVal hpvSource As Long, _
ByVal cbCopy As Long)
Dim gbyteDLData() As Byte
Dim gDataContentLength As Long
==========以上建一個 共用模組.bas==========
Private Sub Inet1_StateChanged(ByVal State As Integer)
On Error GoTo EXITSUB
Select Case State
Case icResponseCompleted '此請求已經完成,並且所有資料均已接收到
Dim tmpB() As Byte
Dim r As Long
DoEvents
'**獲得開頭段資料 及 長度資訊
Dim S As String
If gDataContentLength = 0 Then
gbyteDLData = Inet1.GetChunk(5120, icByteArray)
End If
S = Inet1.GetHeader("Content-Length")
If Len(S) = 0 Then gDataContentLength = 0 Else gDataContentLength = CLng(S)
'**持續拼接資料,直到無資料為止
Do While True
tmpB = Inet1.GetChunk(5120, icByteArray)
If LenB(tmpB) = 0 Then Exit Do
r = UBound(gbyteDLData) + 1
ReDim Preserve gbyteDLData(0 To r + UBound(tmpB))
CopyMemory _
ByVal VarPtr(gbyteDLData(0)) + r, _
ByVal VarPtr(tmpB(0)), _
UBound(tmpB) + 1
Erase tmpB
DoEvents
Loop
End Select
EXITSUB:
If Err.Number = 35758 Then Inet1.Cancel
Err.Clear
Command1.Enabled = True
End Sub
Private Sub Command1_Click()
Command1.Enabled = False
Call StartDownLoad '開始下載副程式
End Sub