Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CopyFileEx problems

Posted on 2000-03-02
5
Medium Priority
?
782 Views
Last Modified: 2011-05-16
I'm trying to set up a std. procedure which will copy a file from one location to another. It HAS to be with CopyFileEx (don't ask me why :-).

I'm having some problems setting up the right types for the various variables, especially the LPVOID ones. If somebody could post an example of how to use the CopyFileEx xall in combination with the CopyProgressRoutine I would really appreciate it

take care
hatecapletters
0
Comment
Question by:hatecapletters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Expert Comment

by:craig_capel
ID: 2576957
WHAT U SAY? YOU HATE CAP LETTERS, YEAH ME TOO!!!... hehe

lol... sorry, just playing, go on... why not use copyfile api?... do you have a bet on withsome or what?....


Craig C. :)

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2576968
CopyFileEx is AFAIK only supported on NT.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2576992
If this is not a problem show us what you have...
0
 
LVL 17

Accepted Solution

by:
inthe earned 400 total points
ID: 2577265
found a couple of exapmples that may help:

 type
   TProgressForm = class(TForm)
     AbortButton: TButton;
     ProgressBar: TProgressBar;
     procedure AbortButtonClick(Sender: TObject);
   private
     { Private declarations }
   public
     { Public declarations }
     FCancel: BOOL;
   end;
   // form has fsStayOnTop formstyle!
 
 implementation
 
 {$R *.DFM}
 
 procedure TProgressForm.AbortButtonClick(Sender: TObject);
 begin
   FCancel := True;
 end;
 
 // Note: could use int64 instead of COMP, but that would make this D4 specific Function
 CopyCallback( TotalFileSize, TotalBytesTransferred,
                       StreamSize, StreamBytesTransferred: COMP;                      
 dwStreamNumber, dwCallbackReason : DWORD;                       hSourceFile,
 hDestinationFile: THandle;
                       progressform: TProgressForm ): DWORD; stdcall; Var
   newpos: Integer;
 Begin
   Result := PROCESS_CONTINUE;
   If dwCallbackReason = CALLBACK_CHUNK_FINISHED Then Begin
     newpos := Round( TotalBytesTransferred / TotalFileSize * 100 );     With
 progressform.Progressbar Do
       if newpos <> Position then
         Position := newpos;
     Application.ProcessMessages;    
   End; { If }
 End; { CopyCallback }
 
 Function DoFilecopy( Const source, target: String ): Boolean;
 Var
   progressform: TProgressForm;
 Begin
   progressform := TProgressform.Create;
   try
     progressform.Show;
     Application.ProcessMessages;
     Result := CopyFileEx(
                 PChar( source ),
                 PChar( target ),
                 @CopyCallback,
                 Pointer( progressform ),
                 @progressform.FCancel,
                 0 );
 finally
   progressform.Hide;
   progressform.free;
 end;
 end; { DoFileCopy }







another example:

type
   LARGE_INTEGER = record
     LowPart : DWORD;
     HighPart : LongInt;
   end;
 
 function CopyProgressRoutine(TotalFileSize : LARGE_INTEGER;
   TotalBytesTransferred : LARGE_INTEGER; StreamSize : LARGE_INTEGER;   StreamBytesTransferred
 : LARGE_INTEGER; StreamNumber : DWORD;
   CallbackReason : DWORD; SourceFile : THandle; DestinationFile : THandle;   Data : pointer):
 DWORD; stdcall;
 begin
   Result := PROGRESS_CONTINUE;
 
   if CallbackReason = CALLBACK_CHUNK_FINISHED then begin
     Form1.Label1.Caption := Format('%f%% complete,',
                                   [(TotalBytesTransferred.LowPart / TotalFileSize.LowPart) *
 100]);
     Form1.Refresh;
   end;
 end;
 
 procedure TForm1.Button1Click(Sender: TObject);
 var
   Cancel : BOOL;
 begin
   Cancel := FALSE;
 
   if not CopyFileEx('C:\WINNT\IE4BAK.DAT',
                   'C:\TEMP\IE4BAK.DAT',
                   @CopyProgressRoutine,
                   nil,
                   @Cancel,
                   COPY_FILE_FAIL_IF_EXISTS)  then
     ShowMessage(SysErrorMessage(GetLastError));
 
 end;

Regards Barry
0
 

Author Comment

by:hatecapletters
ID: 2577737
Excellent, allthough you forgot to write FUNCTION before the copycallback declaration ;-)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question