Microsoft KB Archive/177244

= Asynchronous download of data in an MFC ActiveX control by using Visual C++ =

Article ID: 177244

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition

 Microsoft Visual C++ 4.2 Enterprise Edition

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

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

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

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

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

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

 Microsoft Visual C++ 2005 Express Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul> </li> <li>Microsoft Windows Internet Services (WinInet)</li></ul>

-

<div class="notice_section">

This article was previously published under Q177244

<div class="idea_section">

Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.

<div class="summary_section">

SUMMARY
The Asyndown.exe sample demonstrates asynchronous download of data in an MFC ActiveX control. MFC wraps this asynchronous download process in the CAsyncMonikerFile class.

<div class="moreinformation_section">

MORE INFORMATION
The following files are available for download from the Microsoft Download Center:

Asyndown.exe

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. An Asynchronous moniker provides a way to download data asynchronously over a network. After a download is first requested, Asynchronous Monikers use a callback interface to indicate that data is available. This data can then be read with an Asynchronous Read operation.

A Read operation on an Asynchronous moniker returns immediately even if the operation has not been completed. If there are only 10 bytes available and Read is called with 1K, it does not block but returns with the 10 available bytes at that point in time. It is the caller's responsibility to return later and attempt to read more data when notified through the callback.

MFC wraps this asynchronous download process in the CAsyncMonikerFile class. ActiveX controls can use the CDataPathProperty class, derived from CAsyncMonikerFile, to help implement asynchronous control properties. This sample demonstrates how to set up an asynchronous loop using timers to read the data.

In the function CDataPathProperty::OnDataAvailable, a timer is set to indicate that data is available. When the timer message is received, the sample reads in blocks of 128 bytes and fills an edit control. If data is not available when the timer message is handled, the timer is turned off. OnDataAvailable turns on the timer if more data arrives later.

Please note that the timer duration is intentionally large and data blocks are intentionally small to demonstrate the behavior even with small files.

You can test the control either by using the HTML page with the sample or by inserting the control in a control container and setting the DataPath property. The control is not signed so you need to set your security settings appropriately if you want to test the control. Depending on your security setting, you may still be warned that the control is not safe for scripting.

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Sridhar S. Madhugiri, Microsoft Corporation

Additional query words: softlib

Keywords: kbhowto kbdownload kbfile kbsample KB177244

-

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

© Microsoft Corporation. All rights reserved.