I am trying to use the CopyFileEx function with a callback in order to display a progress bar. However, something does not seem to be working correctly.
When I use the callback function, the CopyFileEx function never returns even after the copy process has completed. Also, the progress bar never gets updated with the progress.
The structure is rather basic:
What really confuses me is the fact that with the callback, CopyFileEx never returns (the trace never happens after the function call), but there are no more traces from the call back function, so it must no longer be reporting statuses after 100%.
I have looked for a few days for a solutions on this, even found solutions that claim to work with code nearly identical to the code I am using, still no dice.
Anyone have any ideas of using CopyFileEx with a callback?
Thanks.
When I use the callback function, the CopyFileEx function never returns even after the copy process has completed. Also, the progress bar never gets updated with the progress.
Code:
UINT CopyThreadFunc( LPVOID pParam )
{
THREADPARAMS* ptp = (THREADPARAMS*)pParam;
HWND hWnd = ptp->hWnd;
CString copyFrom = ptp->copyFrom;
CString copyTo = ptp->copyTo;
delete ptp;
CopyFileEx( copyFrom,
copyTo,
(LPPROGRESS_ROUTINE)CopyProgressRoutine,
(LPVOID)hWnd,
FALSE,
0 );
// Tell the parent to close the dialog
PostMessage( hWnd, WM_CLOSE, 0, 0 );
TRACE( "Ending thread\n" );
return 0;
}
DWORD CALLBACK
CopyProgressRoutine( LARGE_INTEGER TotalFileSize,
LARGE_INTEGER TotalBytesTransferred,
LARGE_INTEGER StreamBytesTransferred,
DWORD dwStreamNumber,
DWORD dwCallbackReason,
HANDLE hSourceFile,
HANDLE hDestinationFile,
LPVOID lpData )
{
double nPercentage = (double(TotalBytesTransferred.QuadPart))/
((double)TotalFileSize.QuadPart)*100;
TRACE( "%0.2f\n", nPercentage );
if( nPercentage >= 100 )
return PROGRESS_CONTINUE;
int nPercent = (int)nPercentage;
::PostMessage( HWND(lpData),
WM_USER_UPDATE_PROGRESS,
nPercent,
0 );
return PROGRESS_CONTINUE;
}
The structure is rather basic:
Code:
typedef struct tagTHREADPARAMS {
HWND hWnd;
CString copyFrom;
CString copyTo;
} THREADPARAMS;
What really confuses me is the fact that with the callback, CopyFileEx never returns (the trace never happens after the function call), but there are no more traces from the call back function, so it must no longer be reporting statuses after 100%.
I have looked for a few days for a solutions on this, even found solutions that claim to work with code nearly identical to the code I am using, still no dice.
Anyone have any ideas of using CopyFileEx with a callback?
Thanks.