Quell
June 16th, 2005, 05:10 AM
Hello.
I tried to make a function that will make a copy of a file:
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:
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
I tried to make a function that will make a copy of a file:
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:
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