|
-
Jun 4th, 2000, 05:25 AM
#1
Thread Starter
New Member
I'm trying to get some kind of file copying function that will display a progress dialog box because I'm copying large files across the network. I've tried using CopyFileEx with a callback function but I can't get the parameters right, it keeps crashing. Here is what I have:
''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Public Const PROGRESS_CONTINUE As Long = 0
Public Const PROGRESS_CANCEL As Long = 1
Public Const PROGRESS_STOP As Long = 2
Public Const PROGRESS_QUIET As Long = 3
Public Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Public Declare Function GetLastError Lib "kernel32" () As Long
Public Declare Function CopyFileExA Lib "kernel32" _
( _
ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
lpProgressRoutine As Long, _
lpData As Long, _
pbCancel As Long, _
ByVal dwCopyFlags As Long _
) As Long
Public Function CopyProgressRoutine _
( _
TotalFileSize As LARGE_INTEGER, _
TotalBytesTransferred As LARGE_INTEGER, _
StreamSize As LARGE_INTEGER, _
StreamBytesTransferred As LARGE_INTEGER, _
ByVal dwStreamNumber As Long, _
ByVal dwCallbackReason As Long, _
hSourceFile As Long, _
hDestinationFile As Long, _
lpData As Long _
) As Long
On Error GoTo EH
Dim filenum As Integer
filenum = FreeFile()
'NOTE: this file is never created(must be crashing before entering this callback function)...
Open "c:\info.txt" For Append As #filenum
Print #1, TotalBytesTransferred.highpart, TotalBytesTransferred.lowpart
Close #filenum
CopyProgressRoutine = PROGRESS_CONTINUE
Exit Function
EH:
CopyProgressRoutine = PROGRESS_CANCEL
MsgBox Err.Number & " - " & Err.Description
End Function
Public Sub Main()
On Error GoTo EH
Dim bCancel As Long, x As Long, y As Long, z As Long
z = 1
x = CopyFileExA("<sourcefile>", "<destfile>", _
AddressOf CopyProgressRoutine, z, bCancel, 0&)
If x = 0 Then
y = Err.LastDllError
x = GetLastError()
MsgBox "GetLastError returned: " & x & vbCrLf & "Err.LastDllError is: " & y
End If
Exit Sub
EH:
MsgBox Err.Number & " - " & Err.Description
End Sub
'''''''''''''''''''''''''''''''''''''''''''''
Is there a better way to display Windows' progress dialog box that is shown when copying large files?
Thanks in advance,
Scott
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
|