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


View products that this article applies to.

This article was previously published under Q223759

↑ Back to the top


Summary

ZipReaderAD demonstrates the use of WinInet byte range requests in an Active Document registered as a "MIME viewer" for the content type of "application/zip" and .zip files. ZipReaderAD 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: 09-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.

ZipReaderAD demonstrates two key concepts: registering an Active Document to act as a MIME viewer of a particular content type and using WinInet to make byte range requests:

Registering Active Document as MIME Viewer

All of the "code" necessary for accomplishing this is shown in the Ziprdrad.cpp file, in the CZipReaderADApp::InitInstance function. This sample uses the SHLWAPI easy registry API functions to add the necessary entries. In particular, the following registry entries are added to the default Active Template Library (ATL) control registry entries:
  • Associate Extension (.zip) with Media Type (application/zip)
    DWORD dwResult = SHSetValue(HKEY_CLASSES_ROOT, _T(".zip"),
          _T("Content Type"), REG_SZ, "application/zip", 15);
    						
  • Registering Media Type to Active Document CLSID and standard file extension
       dwResult = SHSetValue(HKEY_CLASSES_ROOT,
          _T("MIME\\Database\\Content Type\\application/zip"),
          _T("CLSID"), REG_SZ, "{C792F126-DBB8-11D1-A052-00C04F9403D0}", 15);
       dwResult = SHSetValue(HKEY_CLASSES_ROOT,
          _T("MIME\\Database\\Content Type\\application/zip"),
          _T("Extension"), REG_SZ, ".zip", 15);
    						
(ZipReaderAD needs to be run once before use. A setup program should make comparable registry entries so this isn't necessary.)

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 server's IPersistMoniker::Load function. Load is called during the initialization of the document in Internet Explorer 4.0. In this sample, you merely determine whether the actual location of the data is on an HTTP server (byte ranges supported) or from an FTP server (byte range not supported), and then kick 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. Note that unless we're on HTTP, you need to wait for all of the data to be downloaded before attempting byte ranges.

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.

To use this sample, build the program and run its executable once to register the Active Document on the machine. Then, navigate Internet Explorer to a ZIP file on the Internet.

NOTE: This server does not function standalone; it can successfully open files only when hosted in Internet Explorer as an Active Document. The code necessary to convince MFC to open ZIP files during OnOpenDocument is left as an exercise to the reader.

↑ Back to the top


Keywords: kbhowto, kbdownload, kbnavigation, kbactivedocs, kbfile, kbsample, KB223759

↑ Back to the top

Article Info
Article ID : 223759
Revision : 5
Created on : 8/9/2004
Published on : 8/9/2004
Exists online : False
Views : 572