Dec 14, 2012 at 1:57pm UTC
Alright so I'm just trying to figure out how to use the CopyFile() function in C++. So far I can't figure out any of it. What I'm running is:
1 2 3 4 5 6 7 8 9 10
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
CopyFile("C:\\Program Files\\Warcraft III\\War3Inst.log" , "C:\\Program Files\\Argh.log" , 1);
return 0;
}
It seems to run fine, but nothing ever gets copied.
The debug info is:
'copyfiletest.exe': Loaded 'C:\Users\Nick\Desktop\Programming\Projects\copyfiletest\Debug\copyfiletest.exe', Symbols loaded.
'copyfiletest.exe': Loaded 'C:\Windows\System32\ntdll.dll', Symbols loaded (source information stripped).
'copyfiletest.exe': Loaded 'C:\Windows\System32\kernel32.dll', Symbols loaded (source information stripped).
'copyfiletest.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Symbols loaded (source information stripped).
'copyfiletest.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
The program '[2068] copyfiletest.exe: Native' has exited with code 0 (0x0).
Last edited on Dec 14, 2012 at 1:59pm UTC
Dec 14, 2012 at 3:09pm UTC
Also C:\program files directory may be one of those 'special' locations that
need admininstrator rights to be able to create files directly.
Dec 14, 2012 at 3:10pm UTC
Nothing seems to be different with your build. I don't think
DWORD Error = GetLastError();
did anything?
If I add in
cout<<Error<<endl;
though, I get '5', and I have no idea what it means? I'm still a beginner...
Dec 14, 2012 at 3:28pm UTC
Last edited on Dec 14, 2012 at 3:28pm UTC
Dec 14, 2012 at 4:33pm UTC
Yes, what I wanted was that '5' number and guestgulkan is right - You need admin privileges for Vista and 7 to access those folders.
Dec 14, 2012 at 5:19pm UTC
That means you have to run Visual Studio as administrator, as you seem to debug your program.
Dec 15, 2012 at 1:02am UTC
YES! I just ran it as administrator and it is working fine! Thank you so much everyone!