I figured out the problem... my delegate function had a bug... I was dividing
by zero when the filesize of the file being copied was 0.
Note this declaration:
Dim Fpr As New FileProgressRoutine(AddressOf FileProgress)
ORIGINAL
Private Function FileProgress( _
ByVal totalFileSize As Int64, _
ByVal totalBytesTransferred As Int64, _
ByVal streamSize As Int64, _
ByVal streamBytesTransferred As Int64, _
ByVal dwStreamNumber As Int32, _
ByVal dwCallbackReason As Int32, _
ByVal hSourceFile As Int32, _
ByVal hDestinationFile As Int32, _
ByVal lpData As Int32) As Int32
Me.pgAction.Value = Convert.ToInt64((totalBytesTransferred *
100.0 / totalFileSize))
CHANGED
Private Function FileProgress( _
ByVal totalFileSize As Int64, _
ByVal totalBytesTransferred As Int64, _
ByVal streamSize As Int64, _
ByVal streamBytesTransferred As Int64, _
ByVal dwStreamNumber As Int32, _
ByVal dwCallbackReason As Int32, _
ByVal hSourceFile As Int32, _
ByVal hDestinationFile As Int32, _
ByVal lpData As Int32) As Int32
If totalFileSize 0 Then
Me.pgAction.Value = Convert.ToInt64((totalBytesTransferred *
100.0 / totalFileSize))
End If
"hz****@nopost.com" wrote:
I've been executing the CopyFileEx code below in a Windows Application for
several months...
Try
If CopyFileEx(fiSource.FullName, strTargetFile, Fpr, ACTION_COPY, 0,
0) 0 Then
Else
Throw New System.ComponentModel.Win32Exception( _
System.Runtime.InteropServices.Marshal.GetLastWin3 2Error)
End If
Catch ex As Exception
msgbox ex.Message
End Try
But now its bombing when it encounters a file containing 0 bytes. The error
message I'm getting is:
Run-time exception thrown : System.OverflowException - Value was either
too large or too small for an Int32.
Any idea why the CopyFileEx return value is causing an overflow? How can I
deal with this problem?
Any help would be greatly appreicated!