473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

CopyFileEx error...

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!

Jul 13 '06 #1
2 2285
>Any idea why the CopyFileEx return value is causing an overflow? How can I
deal with this problem?
Probably due to an incorrect API declaration. The return type should
be a Boolean.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 13 '06 #2
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!
Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
2
by: H Glenn Hatfield | last post by:
I know this has come up a couple of times on the group, but I'm still having trouble with it. I'm fine with creating the delegate and CopyFileEx declarations and the function which gets...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
3
by: Paul | last post by:
I have been trying to code a callback in vb.net using the delegate method. I have successfully compiled the program and run it but after it accessess the copyfileex winapi method and then calls the...
2
by: =?Utf-8?B?dGFpbG9jaGlr?= | last post by:
I have a VB6 project that call CopyFileEx with ProgressRoutine to display the progress. The code is like this 'Copy the file to the destination folder lpCallBack = AddressOf CopyProgressCallback...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.