Platform SDK: Broadcast Architecture

Co-creating a Package Class Instance

The CATVEFPackage class implements a single interface, IATVEFPackage, that provides methods for creating gzip-compressed, MIME-encoded "packages" or archives of enhancement files (such as the HTML pages, graphics, scripts, and so on). This simplified example illustrates the sequence for co-creating a package object and obtaining its interface. Error checking has been omitted for the sake of simplicity.

    HRESULT hr;
    IUnknown* pIUnknown;
    IATVEFPackage* pIPackage;
 
    hr = CoCreateInstance (
        CLSID_CATVEFPackage,
        NULL,
        CLSCTX_SERVER,
        IID_IUnknown,
        (void **) & pIUnknown
        );
 
    hr = pIUnknown -> QueryInterface(
        IID_IATVEFPackage,
        (void **) & pIPackage
        );

If you will be transmitting multiple packages, create multiple CATVEFPackage objects, one to hold each package. Since compressing the files into packages can be a lengthy process, you must take care to ensure that you create all the packages far enough in advance of when they will be sent. The following code example illustrates how to use multiple CATVEFPackage objects.

// Supporting multiple packages
IATVEFPackage    * pIPackage [MAX_PACKAGES] ;
 
for (int i = 0; i < MAX_PACKAGES; i++) {
  hr = CoCreateInstance (
       CLSID_CATVEFPackage,
       NULL,
       CLSCTX_SERVER,
       IID_IATVEFPackage,
       (void **) & pIPackage [i]
       ) ;
  if (FAILED (hr)) {
    break ;
  }
}
 
// Now each pIPackage [i] has a pointer to IATVEFPackage 
// in different objects, and thus different packages.  After 
// compressing the desired files and closing the packages, you could
// transmit the files as follows.
 
for (int i = 0; i < MAX_PACKAGES; i++) {
  hr = pISend -> SendPackage (pIPackage [i]) ;
  if (FAILED (hr)) {
    break ;
  }
}

Note that the CATVEFPackage object is used to create and initialize a new package, add files to it, and then close it after all files have been added. The actual sending of the closed package is handled through the IATVEFSend interface, which is implemented by CSendATVEFInserter and CSendATVEFMulticast.