HRESULT bitsCopyFile( LPWSTR wszTargetPath, LPWSTR wszLocalPath ) { IBackgroundCopyManager* g_XferManager = NULL; GUID JobID; IBackgroundCopyJob* pJob = NULL; HANDLE hTimer = NULL; LARGE_INTEGER liDueTime; IBackgroundCopyError* pError = NULL; WCHAR* pszDescription = NULL; HRESULT hr = CoCreateInstance(__uuidof(BackgroundCopyManager),NULL,CLSCTX_SERVER,__uuidof(IBackgroundCopyManager),(void**) &g_XferManager ); if( SUCCEEDED(hr) ) { hr = g_XferManager->CreateJob(L»SampleBITSUploadJob», BG_JOB_TYPE_UPLOAD, &JobID, &pJob); if( SUCCEEDED(hr) ) { hr = pJob->AddFile( wszTargetPath,wszLocalPath ); if( SUCCEEDED(hr) ) { if( SUCCEEDED(hr) ) { liDueTime.QuadPart = -10000000; //Poll every 1 second hTimer = CreateWaitableTimer(NULL, FALSE, «MyTimer»); SetWaitableTimer(hTimer, &liDueTime, 1000, NULL, NULL, 0); BOOL bIsLoop = TRUE; while( bIsLoop ) { WaitForSingleObject( hTimer,INFINITE ); BG_JOB_STATE jobState; hr = pJob->GetState( &jobState ); if( SUCCEEDED( hr ) ) { switch( jobState ) { case BG_JOB_STATE_TRANSFERRED: printf( «Transfered » ); bIsLoop = FALSE; break; case BG_JOB_STATE_SUSPENDED: hr = pJob->Resume(); break; case BG_JOB_STATE_TRANSFERRING: BG_JOB_PROGRESS pVal; hr = pJob->GetProgress( &pVal ); if( SUCCEEDED( hr ) ) { printf( «%d »,DWORD((pVal.BytesTransferred * 100)/pVal.BytesTotal) ); } break; case BG_JOB_STATE_QUEUED: printf( «Queued » ); break; case BG_JOB_STATE_CONNECTING: printf( «Connecting » ); break; case BG_JOB_STATE_ERROR: case BG_JOB_STATE_TRANSIENT_ERROR: hr = pJob->GetError( &pError ); if( SUCCEEDED( hr ) ) { hr = pError->GetErrorDescription( GetThreadLocale(),&pszDescription ); if( SUCCEEDED( hr ) ) { wprintf( L»%s »,pszDescription ); CoTaskMemFree(pszDescription); } pError->Release(); pError = NULL; } bIsLoop = FALSE; break; case BG_JOB_STATE_ACKNOWLEDGED: break; case BG_JOB_STATE_CANCELLED: break; } } } } } } } return hr; }