BITS DOWNLOADS Sample

Summary

This sample demonstrates the use of new BITS APIs to download files.

Program flow

  1. DOWNLOADS.cpp begins by determining that the correct number of arguments has been used on the command line. If not, a usage summary is output and the program ends.
  2. The next step is to initialize COM. Note that the security level is then set to RPC_C_IMP_LEVEL_IMPERSONATE. This is the lowest security level that will work for our purposes.
  3. If all of that goes correctly, we then instanciate an instance of IBackgroundCopyManager. In effect, this puts us in communication with the BITS processes that may be running in the test machine. If any of these fail, a suitable message is output, and the job ends.
  4. We use the IBackgroundCopyManager to create a new BITS job. In doing so, we pass it the name we wish to use for the job, and an enumeration telling the manager that it is a download job. When it returns, assuming a good completion code, it will pass back a new Globaly Uniquie Identifier (GUID), and a pointer to another COM object that is an IBackgroundCopyJob.
  5. In the downloads.h file, we described a class named CNotifyInterface. CNotifyInterface inherits from IBackgroundCopyCallback2. We use this newly instanciated object by telling the IBackgroundCopyJob to set it as our Notify Interface. This Notify Interface will be called when certain events occur.
  6. Next the remote and local file names are added.
  7. Once files have been added to the job, the job is “Resumed”. This command tells the job to begin its work.
  8. Downloads.cpp is now almost done. This main thread falls into a dispatch loop, looking for a WM_QUIT message, and dispatching any other messages it finds.

Key Concepts

Build/Configuration instructions

Basic Usage

System configuration