Microsoft KB Archive/223759

= SAMPLE: Ziprdrad.exe: Active Document MIME Reader Uses Byte Ranges =

Article ID: 223759

Article Last Modified on 8/9/2004

-

APPLIES TO

 Microsoft Internet Explorer 4.0 128-Bit Edition Microsoft Internet Explorer 4.01 Service Pack 2 Microsoft Internet Explorer 4.01 Service Pack 1 Microsoft Internet Explorer 4.01 Service Pack 2 Microsoft Internet Explorer 5.0 Microsoft Internet Explorer 5.5 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

<ul> Microsoft Visual C++ 6.0 Professional Edition</li></ul>

<ul> Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q223759

<div class="summary_section">

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.

<div class="moreinformation_section">

MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

Ziprdrad.exe

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:

<ul>  Associate Extension (.zip) with Media Type (application/zip) DWORD dwResult = SHSetValue(HKEY_CLASSES_ROOT, _T(".zip"),     _T("Content Type"), REG_SZ, "application/zip", 15); </li>  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); </li></ul>

(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.

Keywords: kbhowto kbdownload kbnavigation kbactivedocs kbfile kbsample KB223759

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.