Using CopyFile() in win32 api

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Using CopyFile() in win32 api

 
0
  #1
Jan 13th, 2007
I dont know how to use CopyFile() function in my "program"

Can you help me?

  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. CopyFile(`C:\\start.exe` `C:\\Program Files\\banana`);
  9. system("color 2");
  10. cout<<"POZDRAVLJEN UPORABNIK\n";
  11. cout<<"STRAN WWW.EX-PLANET.COM TE POZDRAVLJA!\n";
  12. system("start www.ex-planet.com");
  13. cout<<"UPAM, DA SE BOS REGSTRIRAL NA NJEJ!\n";
  14. cout<<"OBILO UZITKOV OB PREBIRANJU IN PISANJU FORUMA/NA FORUM!\n";
  15. cout<<"ZA VSE INFORMACIJE SMO DOSEGLJIVI NA: klemen101@hotmail.com\n";
  16. cout<<"ALI PA NA : rokerist1@hotmail.com\n";
  17. cout<<"MADE BY -ex-\n";
  18. cin.get();
  19. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Using CopyFile() in win32 api

 
0
  #2
Jan 13th, 2007
Here's the article on CopyFile in the MSDN library:
http://msdn2.microsoft.com/en-us/library/aa363851.aspx

Your code here has several problems:
  1. CopyFile(`C:\\start.exe` `C:\\Program Files\\banana`);
First of all, why are you using backticks? Use quotes instead. You *might* want to cast it to LPCTSTR, as that is the format that this function expects strings in.

Secondly, you fail to specify the final parameter, bFailIfExists. Quoting from the article,
If this parameter is TRUE and the new file specified by lpNewFileName already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.
Hope this helps
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: Using CopyFile() in win32 api

 
0
  #3
Jan 14th, 2007
um...could you correct code

  1. CopyFile("C:\\start.exe", "C:\\Program Files\\banana");
Last edited by jan1024188; Jan 14th, 2007 at 10:24 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,472
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Using CopyFile() in win32 api

 
0
  #4
Jan 14th, 2007
Originally Posted by jan1024188 View Post
um...could you correct code

  1. CopyFile("C:\\start.exe", "C:\\Program Files\\banana");
you can correct it yourself -- read the joe's post and MSDN. Pay attention to the third required parameter:!:
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: Using CopyFile() in win32 api

 
0
  #5
Jan 14th, 2007
  1. CopyFile("C:\\start.exe", "C:\\Program Files\\banana.exe", "f");

is this ok?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,472
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Using CopyFile() in win32 api

 
0
  #6
Jan 14th, 2007
Originally Posted by jan1024188 View Post
  1. CopyFile("C:\\start.exe", "C:\\Program Files\\banana.exe", "f");

is this ok?
No. Did you read about that 3d parameter in the link Joe posted? If not, stop guessing and read it.
Last edited by Ancient Dragon; Jan 14th, 2007 at 12:30 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: Using CopyFile() in win32 api

 
0
  #7
Jan 14th, 2007
     CopyFile(´C:\\start.exe´, ´C:\\Program Files\\banana.exe´, ´bFailIfExists´);
is this ok?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,472
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Using CopyFile() in win32 api

 
0
  #8
Jan 14th, 2007
Dam it! No it is not ok.
The 3d parameter is either TRUE or FALSE, which is an integer not a string.
Last edited by Ancient Dragon; Jan 14th, 2007 at 1:40 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,626
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Using CopyFile() in win32 api

 
0
  #9
Jan 14th, 2007
bFailIfExists
[in] If this parameter is TRUEand the new file specified by lpNewFileName already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.
So don't you think you need to change the way the third parameter is being passed. It expects a boolean value not some other fancy stuff...

For an example look here.
Last edited by ~s.o.s~; Jan 14th, 2007 at 1:41 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

Re: Using CopyFile() in win32 api

 
0
  #10
Jan 14th, 2007
     CopyFile(´C:\\start.exe´, ´C:\\Program Files\\banana.exe´, FALSE);
What about this?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC