Bool tform1: copyfile2 (){
Ansistring srcpath = extractfilepath (Application-> exename) + "windows.pdf ";
Ansistring destpath = extractfilepath (Application-> exename) + "dest.pdf ";
Handle hsrcfile, hdestfile;
Hsrcfile = createfile (srcpath. c_str (), // open myfile. txt
Generic_read, // open for reading
File_pai_read, // share for reading
Null, // No security
Open_existing, // existing file only
File_attribute_normal, // normal file
Null); // No ATTR. Template
If (hsrcfile = invalid_handle_value)
Return false;
Hdestfile = createfile (destpath. c_str (), // create myfile. txt
Generic_write, // open for writing
0, // do not share
Null, // No security
Create_always, // overwrite existing
File_attribute_normal, // normal file
Null );
If (hdestfile = invalid_handle_value)
Return false;
Char * buffer = new char [1024];
Ulong lpnumberofbytesread, lpnumberofbyteswritten;
DWORD filesize, offset = 0;
Filesize = getfilesize (hsrcfile, null );
If (filesize = invalid_file_size)
Return false;
While (offset <filesize ){
Bool bflag = readfile (hsrcfile, buffer, 1024, & lpnumberofbytesread, null );
If (! Bflag ){
Return false;
}
Writefile (hdestfile, buffer, 1024, & lpnumberofbyteswritten, null );
Offset ++ = 1024;
}
Closehandle (hsrcfile );
Closehandle (hdestfile );
Delete [] buffer;
Return true;
}