Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 30th, 2007, 12:00 PM   #1
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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);
Should I be learning sockets instead since I an trying to copy a file from one copmuter to another?

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.
badbasser98 is offline   Reply With Quote
Old Oct 30th, 2007, 1:00 PM   #2
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
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
Prm753 is offline   Reply With Quote
Old Oct 31st, 2007, 10:50 AM   #3
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Old Oct 31st, 2007, 12:15 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: problems with CopyFileEX

You have to write your own CopyProgressRoutine. You need to define it as specified:
Quote:
Originally Posted by MSDN
DWORD CALLBACK CopyProgressRoutine(
  [in]                 LARGE_INTEGER TotalFileSize,
  [in]                 LARGE_INTEGER TotalBytesTransferred,
  [in]                 LARGE_INTEGER StreamSize,
  [in]                 LARGE_INTEGER StreamBytesTransferred,
  [in]                 DWORD dwStreamNumber,
  [in]                 DWORD dwCallbackReason,
  [in]                 HANDLE hSourceFile,
  [in]                 HANDLE hDestinationFile,
  [in]                 LPVOID lpData
);
Obviously, you can change the names to anything you like.
__________________
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
DaWei is offline   Reply With Quote
Old Feb 15th, 2008, 1:35 PM   #5
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Old Feb 15th, 2008, 2:47 PM   #6
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 93
Rep Power: 1 null_ptr0 is on a distinguished road
Re: problems with CopyFileEX

LARGE_INTEGER maybe doesn't define operator/(const LARGE_INTEGER)?
null_ptr0 is offline   Reply With Quote
Old Feb 27th, 2008, 1:36 PM   #7
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Old Feb 27th, 2008, 5:43 PM   #8
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
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
Cache is offline   Reply With Quote
Old Mar 20th, 2008, 3:14 PM   #9
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Old Mar 20th, 2008, 3:47 PM   #10
Arla
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 208
Rep Power: 4 Arla is on a distinguished road
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).
Arla is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:48 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC