![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
problems with CopyFileEX
This is my first time trying to copy a file using code. I am having trouble getting the function call correct. Could someone please look at what I am doing wrong?
BOOL WINAPI CopyFileEx(
LPCTSTR "\\\\PC1\\Directory\\filename.pdf",
LPCTSTR "\\\\PC2\\Directory\\filename.pdf",
LPPROGRESS_ROUTINE NULL,
LPVOID NULL,
LPBOOL false,
DWORD COPY_FILE_FAIL_IF_EXISTS | COPY_FILE_RESTARTABLE);This is on a Win XP Pro SP2 box using Dev-C++ 4.9.9.2 Thanks, -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Re: problems with CopyFileEX
Take out the types. I can't even compile with them in there. The function has already been written in windows.h, just call it. For example:
CopyFileEx("C:\\Dev-Cpp\\1.txt", "C:\\2.txt", NULL, NULL, false, COPY_FILE_FAIL_IF_EXISTS | COPY_FILE_RESTARTABLE);Works fine for me to copy and paste on a local computer. Dev-C++ 4.9.9.2 here as well.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Re: problems with CopyFileEX
Thanks for the reply. I included the types in my post to try and be as clear as I could in the post. I did not have the types in my function though I did have a typo I found.
On another note, I am trying to use the CopyProgressRoutine CALLBACK. As usual, I am in in a bit over my head. I haven't a clue where to start to get it working. Do I have to declare and define the function in my code? I have visited MSDN, but feel like an idiot because I cannot make heads or tails of what its telling me Does anyone know of a tutorial or other guide to help me understand its use? thanks, -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#4 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: problems with CopyFileEX
You have to write your own CopyProgressRoutine. You need to define it as specified:
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Re: problems with CopyFileEX
Its been a while since I have been able to work on this program, but have got back into it yesterday. I have the copy and callback functions working, I am having trouble calculating the percentage of the file that's being copied however. I am using that data to increment a progressbar. Through some research it appears that the problem is with the LARGE_INTEGER type.
Does anyone have any documentation (or links) on how to use math functions with that type? I was hoping it was going to be as easy as Percent = (TotalFileSize / TotalBytesTransferred) * 100; It obviously isn't since I get the error no match for 'operator/' in 'TotalFileSize / TotalBytesTransferred' Thank you for your help thus far ![]()
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#6 |
|
12 years old
Join Date: Nov 2007
Posts: 93
Rep Power: 1
![]() |
Re: problems with CopyFileEX
LARGE_INTEGER maybe doesn't define operator/(const LARGE_INTEGER)?
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Re: problems with CopyFileEX
anyone have a clue what's going on with this?
Thanks
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#8 |
|
Hobbyist
Join Date: Sep 2005
Posts: 261
Rep Power: 4
![]() |
Re: problems with CopyFileEX
LARGE_INTEGER is a union type. You have to access it's data members which are actually numeric types.
example: LARGE_INTEGER x, y; LONGLONG z = (x.QuadPart / y.QuadPart) * 100; http://msdn2.microsoft.com/en-us/lib...13(VS.85).aspx |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Re: problems with CopyFileEX
Thanks Cache, that works though I am still having problems with it working for some reason.
I have resorted to setting individual variables equal to each part and number that is included in the math portion of figuring the amount of the file that has been copied. I have set TotalFileSize.QuadPart equal to Total and TotalBytesTransfered.QuadPart equal to Transfer. If I look at either of these values at each call to the progress routine, Total is the correct size of the file and Transfer is increasing in size appropriately until it is equal to Total when the copy function ends. I have a few other variables: Divide, Percent, & Hundred. Divide is a float, Percent is an int and Hundred is an int whose value is 100. This is the bit of math I have in my CALLBACK_CHUNK_FINISHED: Divide = (Transfer / Total); Percent = (Divide * Hundred); I have also tried: Percent = ((Transfer / Total)*(Hundred)); With either method, at any step in the progress Divide is zero and Percent is zero in which Total and Transfer are their correct values. The only time Percent is not zero is when the process is complete and Transfer and Total are equal. Obviously Percent then equals 100 and the progress bar is stepped to the end. This makes no sense to me at all. Anyone know something else I can try, or am I overlooking something simple again? Thanks, ~BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 208
Rep Power: 4
![]() |
Re: problems with CopyFileEX
My guess (and it is a guess) is that Total and Transfer are ints (or some variant like that) and when you divide one by the other the result is an int (even if you put it into a float, it's doing integer division)
Try it, I wrote a quick program that did int a = 5; int b = 6; float c = a/b; Result is 0 because a and b are ints. have to do c = (float)a/(float)b (or something like that, I'm using C# so syntax may be slightly different). |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| std::cout problems | rwm | C++ | 6 | Jul 2nd, 2007 2:39 AM |
| problems loading 2 dlls in Delphi7 | nico765 | Delphi | 0 | Jan 7th, 2006 3:03 PM |
| 2 problems on permutations | alejandrito | Assembly | 0 | Dec 15th, 2005 3:07 AM |
| New Switch, FTP Problems | ViOLATiON | Coder's Corner Lounge | 6 | Sep 13th, 2005 1:44 PM |
| C++ and Fortran Compilation problems | wallygato11 | C++ | 0 | Jul 8th, 2005 10:44 PM |