1

I made an application which copies files, usually large files. I want to show the progress of the copying, but i can't it bring to work. Can someone tell me what i am doing wrong? Now it works very interesting. The % goes to 49% than, back to 0, and then to 40, then again back to 0 and then back 35, and this goes on, untill it copied successfully the file, but i don't understand why get i such a weird percetage. This could be because i calculate the percent variable like i do it later? If i want to calculate percent this way : percent = TotalBytesTransferred*100/TotalFileSize; then i get a compiler error : "error C2676: binary '*' : 'LARGE_INTEGER' does not define this operator or a conversion to a type acceptable to the predefined operator" and this is the reason why i calculate is this way.

Thanks in advance!

kampi

Code:

UINT CopyThread( LPVOID pParam )
{
 ....
 ....
 ....
 ret = CopyFileExA( Address.from, Address.to, &MyCopyProgressRoutine, ptr, FALSE,FALSE);
 ....
 ....
}  

DWORD CALLBACK MyCopyProgressRoutine(
LARGE_INTEGER TotalFileSize, // file size
LARGE_INTEGER TotalBytesTransferred, // bytes transferred
LARGE_INTEGER StreamSize, // bytes in stream
LARGE_INTEGER StreamBytesTransferred, // bytes transferred for stream
DWORD dwStreamNumber, // current stream
DWORD dwCallbackReason, // callback reason
HANDLE hSourceFile, // handle to source file
HANDLE hDestinationFile, // handle to destination file
LPVOID lpData // from CopyFileEx
)
{
 TCHAR currentprog[20];

 CGetFileListDlg* ptr = (CGetFileListDlg*)lpData;
 // do something with pointer, e.g. ptr->m_Progressbar.Pos blahblah 

 //ptr->m_fileprog.Clear();
//ptr->UpdateWindow();
 DWORD percent = (TotalBytesTransferred.HighPart*2^31 + TotalBytesTransferred.LowPart) * 100/(TotalFileSize.HighPart*2^31 + TotalBytesTransferred.LowPart);

wsprintf( currentprog, _T("%d %%"),percent );
ptr->m_fileprog.SetWindowText( currentprog );

return  PROGRESS_CONTINUE;
}
kampi
  • 2,362
  • 12
  • 52
  • 91

3 Answers3

0
__int64 percent = (TotalBytesTransferred.HighPart * 2147483648 + TotalBytesTransferred.LowPart) * 100 / (TotalFileSize.HighPart * 2147483648 + TotalFileSize.LowPart);

you have logical mistake! TotalBytesTransferred change to TotalFileSize

andrew
  • 18
  • 3
0

I use:

int percent = floor ((100.0 * (float)TotalBytesTransferred.QuadPart / (float)TotalFileSize.QuadPart));
double-beep
  • 5,031
  • 17
  • 33
  • 41
ndsoft
  • 1
0

Percent calculation can be made using

uint64_t  percent= ((uint64_t)TotalBytesTransferred.HighPart<<32 + TotalBytesTransferred.LowPart) * 100/((uint64_t)TotalFileSize.HighPart<<32 + TotalFileSize.LowPart);

(Prevents hardcoding of a value for 2^32)

David Buck
  • 3,752
  • 35
  • 31
  • 35
code
  • 1
  • 1