SAMPLE: Ziprdr.exe: ZipReader ActiveX Control MIME Viewer Uses Byte Ranges

ID: Q223500


The information in this article applies to:
  • Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 4.01 SP1, 4.01 SP2, 5
  • The Microsoft Active Template Library (ATL) 3.0, included with:
    • Microsoft Visual C++, 32-bit Editions, version 6.0


SUMMARY

ZipReader (Ziprdr.exe) is a sample that demonstrates the use of WinInet byte range requests in an ActiveX control registered as a "MIME viewer" for the content type of "application/zip" and .zip files. ZipReader uses byte range requests to retrieve the list of file contents in a ZIP archive from supporting servers without requiring a download of the entire file to the client.


MORE INFORMATION

The following file is available for download from the Microsoft Download Center. Click the file name below to download the file:

Ziprdr.exe
Release Date: Mar-23-1999

For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.

ZipReader demonstrates two key concepts, registering an ActiveX control to act as a MIME viewer of a particular content type and using WinInet to make byte range requests. Also, ZipReader demonstrates a key limitation of ActiveX controls as MIME viewers: as of the current version of Internet Explorer 4.0, Internet Explorer fails to instantiate the control when content is retrieved from a non-HTTP source such as an FTP server.

Registering ActiveX Control as MIME Viewer

All of the code necessary for registering an ActiveX control as a MIME viewer is shown in the ZipReader.rgs file, the auto-registration file used by the Active Template Library (ATL). In particular, the following registry entries are added to the default ATL control registry entries:
  • Associate Extension (.zip) with Media Type (application/zip)
    
    ForceRemove .zip = s 'ziprdr.ZipReader'
       {
          ForceRemove val 'Content Type' = s 'application/zip'
       } 
  • Registering Media Type to ActiveX control CLSID and standard file extension
    
    NoRemove MIME
       {
          NoRemove Database
          {
             NoRemove 'Content Type'
             {
                ForceRemove 'application/zip'
                {
                   val Extension = s '.zip'
                   val CLSID = s '{A6C73397-D96F-11D1-96FF-00C04FB9C3AB}'
                }
             }
          }
       } 
  • Enabling full-page support (informs Internet Explorer that this control acts as a MIME viewer. That is, it is activated in response to the registered content type, and Internet Explorer should give it the full client area for rendering its data.
    
    NoRemove CLSID
       {
       ForceRemove {A6C73397-D96F-11D1-96FF-00C04FB9C3AB} = s 'ZipReader Class'
          {
             ForceRemove 'EnableFullPage'
             {
                ForceRemove .zip
             }
          }
       } 

Using WinInet to Make Byte-Range Requests

The code for interacting with remote zip files is spread out over three main areas.

First, Zipparse.cpp and Zipparse.h contain functions specialized to parsing sections of data from the ZIP file. All of these functions assume the data is available already in a special buffer and none make any download requests. Read through this code at your leisure.

Second, the download is actually initiated in the control's IPersistStreamInit::InitNewor IPersistMoniker::Load method. IPSI::InitNew is called during the initialization of the control in Internet Explorer 4.0x when the browser is navigated directly to a ZIP file. IPM::Load is called in the more unusual case when the control is hosted using the <OBJECT> tag and given a DATA URL. In this sample, from both starting locations, you call LoadFromMoniker. LoadFromMoniker merely determines whether the actual location of the data is on an HTTP server (byte ranges supported) or otherwise (byte range not supported), and then kicks off the appropriate code path. CentralDirectoryRangeHelper is used for byte ranges, and is the main focus of this sample. CentralDirectoryStreamHelper does no byte ranges and uses a basic moniker binding to the data.

Last, the actual byte range work is done in RangeRequest, which is called by CentralDirectoryRangeHelper twice--first to get the last 22 bytes necessary for finding the number of bytes needed for the ZIP file's central directory and then to get the central directory. RangeRequest does pretty simple work: it adds the Range header during an InternetOpenURL call and then uses InternetReadFile to read the resultant data into a buffer.

NOTE: In some rare circumstances, Internet Explorer fails to activate ActiveX controls (or plugins) even though it recognizes that an ActiveX control or plugin is needed to view a particular Media Type. When this occurs, Internet Explorer displays an empty client area with a small icon in the upper left corner. Some of these rare situations are not preventable, such as when servicing data during some redirected requests, except by creating an Active Document instead of an ActiveX control. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
Q223759 SAMPLE: Ziprdrad.exe Active Document MIME Reader Uses Byte Ranges


REFERENCES

For more information, see the following in the Microsoft Web Workshop:

Web Workshop: Component Development, ActiveX Controls, Registering an ActiveX Object as the Player for a Media Type

Additional query words:

Keywords : kbfile kbsample kbActiveX kbCtrl kbCtrlCreate kbIE400 kbIE401 kbVC600 kbWinInet kbATL300 kbIE401sp1 kbIE401sp2 kbGrpInet kbIE500
Version : WINDOWS:3.0,4.0,4.01,4.01 SP1,4.01 SP2,5
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: January 13, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.