|
-
June 16th, 2005, 05:10 AM
#1
Copying File Manualy
Hello.
I tried to make a function that will make a copy of a file:
Code:
sFile sfFile;
sfFile.chFile=new CH[strlen(chFile)*sizeof(CH)];
memcpy(sfFile.chFile,chFile,strlen(chFile)*sizeof(CH));
sfFile.hFile=CreateFile(chFile,FILE_ALL_ACCESS,NULL,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(sfFile.hFile == INVALID_HANDLE_VALUE)Log("Invalid Handle on CreateFile");
sfFile.dwSize=GetFileSize(sfFile.hFile,NULL);
sfFile.uchData=new unsigned char[sfFile.dwSize];
if(ReadFile(sfFile.hFile,sfFile.uchData,sfFile.dwSize,&sfFile.dwSizeRead,0)==0)Log("Erro on Reading FIle");
FILE *store_point;
store_point=freopen("copy.exe","w",stdout);
for(int i=0;i<sfFile.dwSize;i++){
cout<<sfFile.uchData[i];
}
Where the structure is:
Code:
typedef struct sFile{
unsigned char *uchData;
CH *chFile;
HD hFile;
DW dwSize;
DW dwSizeRead;
};
Ch=char
Basicly teh output i get is close to the right one, it is 1 kb over the size but the file is no longer executable, if i try to copy an executable file.
I don't want to use winapi for copying files......
Anyways, any ideas where i made a mistake?
Thx alot in advance
-
June 16th, 2005, 05:25 AM
#2
Re: Copying File Manualy
i understand u dont want to use winpai to copy the file, but what about
Code:
system("copy filename1 filename2").
?
if i helped dont forget to rate :-)
Cheers
-
June 16th, 2005, 05:29 AM
#3
Re: Copying File Manualy
btw if you using ::CreateFile(..) why not using ::CopyFile(..)??
Cheers
-
June 16th, 2005, 05:54 AM
#4
Re: Copying File Manualy
i just wanan make some changes to teh file->compress it, but i need to be able to output teh file.
so any ideas where i made a mistake.
and thx for your answers and alt solutions
-
June 16th, 2005, 06:04 AM
#5
Re: Copying File Manualy
If text files seem to be copied OK, and binary files fail to get copied, make sure that you open your new file in binary mode, and not text mode. If you are using defaults, check what they are.
Hob
B+!
'There is no cat' - A. Einstein
Use [code] [/code] tags!
Did YOU share your photo with us at CG Members photo gallery ?
-
June 16th, 2005, 06:05 AM
#6
Re: Copying File Manualy
I'm not familiar with any of the windows API file handling routines,
but typically the problem you describe occurs when the output
file is not opened in binary mode.
-
June 16th, 2005, 12:42 PM
#7
Re: Copying File Manualy
thx alot i asked the question in winapi section about the mode, the msdn does not specify any of this info.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|