Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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

View products that this article applies to.


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.

↑ Back to the top

More information

The following file is available for download from the Microsoft Download Center:
Release Date: Mar-23-1999

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

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:
223759 SAMPLE: Ziprdrad.exe Active Document MIME Reader Uses Byte Ranges

↑ Back to the top

Article Info
Article ID : 223500
Revision : 4
Created on : 1/1/0001
Published on : 1/1/0001
Exists online : False
Views : 406