×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CopyFileEx with callback never returns

CopyFileEx with callback never returns

CopyFileEx with callback never returns

(OP)
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.

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.

RE: CopyFileEx with callback never returns

As far as I know, CopyProgressRoutine has 9 parameters.
The 3rd parameter is LARGE_INTEGER StreamSize...

It seems you convert a pointer to invalid function to LPPROGRESS_ROUTINE type in C-style cast...
 

RE: CopyFileEx with callback never returns

(OP)
Uggggh...apparently my eyes aren't as good as I thought they were.

Thanks ArkM.  That did the trick.

I looked at the MSDN documentation for the callback function prototype countless times and never noticed I missed the StreamSize parameter...

Thanks again.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close