I dont know how to use CopyFile() function in my "program"

Can you help me?

#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    CopyFile(`C:\\start.exe` `C:\\Program Files\\banana`);
    system("color 2");
  cout<<"POZDRAVLJEN UPORABNIK\n";
  cout<<"STRAN WWW.EX-PLANET.COM TE POZDRAVLJA!\n";
  system("start www.ex-planet.com");
  cout<<"UPAM, DA SE BOS REGSTRIRAL NA NJEJ!\n";
  cout<<"OBILO UZITKOV OB PREBIRANJU IN PISANJU FORUMA/NA FORUM!\n";
  cout<<"ZA VSE INFORMACIJE SMO DOSEGLJIVI NA: klemen101@hotmail.com\n";
  cout<<"ALI PA NA : rokerist1@hotmail.com\n";
  cout<<"MADE BY -ex-\n";
  cin.get();
}

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:

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

um...could you correct code

CopyFile("C:\\start.exe", "C:\\Program Files\\banana");

um...could you correct code

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:!:

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.

CopyFile(´C:\\start.exe´, ´C:\\Program Files\\banana.exe´, [I]´[/I][I]bFailIfExists[/I]´);

is this ok?

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.

CopyFile(´C:\\start.exe´, ´C:\\Program Files\\banana.exe´, [I]FALSE[/I]);

What about this?

CopyFile(´C:\\start.exe´, ´C:\\Program Files\\banana.exe´, [I]FALSE[/I]);

What about this?

what does your compiler say about it? Does it produce a warning or erro message?

Looks good except for the way you have specified the file names -- don't use single quotes, use double quotes to specify C style null terminated strings.

This article has been dead for over six months. Start a new discussion instead.