SAMPLE: How To Do Asynchronous WinInet with MFC ClassesLast reviewed: September 30, 1997Article ID: Q164983 |
The information in this article applies to:
SUMMARYThe MFC WinInet classes (CInternetSession, CInternetConnection, etc.) are not designed to be used with asynchronous WinInet connections or file transfer. Instead, developers looking for asynchronous-like behavior in their MFC WinInet application should implement separate synchronous WinInet sessions in secondary threads. In the event that asynchronous WinInet using MFC is necessary, the ASYNCGET sample demonstrates some techniques for manipulating the MFC classes to do this. The following file is available for download from the Microsoft Software Library:
~ Asyncget.exe (size: 37220 bytes)For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591 TITLE : How to Obtain Microsoft Support Files from Online Services MORE INFORMATIONA WinInet application creates an asynchronous WinInet session by using INTERNET_FLAG_ASYNC in the last parameter of the CInternetSession constructor, dwFlags. Because some Internet operations may take a long period of time to complete, it is often desirable to make asynchronous WinInet calls, which return control to the application and run the operation in the background. This allows the application's user interface to continue to function. In addition, the application can display status updates on a lengthy download or even allow the user to halt an operation while it is executing. In this case, the recommended method for an MFC WinInet application is to not use INTERNET_FLAG_ASYNC in constructing the CInternetSession. Instead, for each necessary concurrent session, a secondary thread is spawned from the main thread. Each secondary thread is responsible for creating a new CInternetSession object without the INTERNET_FLAG_ASYNC flag and then performing any needed operations on that synchronous session, such as making an FTP connection and then downloading a file. In some cases however, true asynchronous WinInet is really the desired goal. If this is the case, developers are encouraged to abandon their use of the MFC WinInet classes and make calls to the WinInet API directly. You can get more information about this from the Internet Client SDK at:
http://www.microsoft.com/msdn/sdk/inetsdk/help/default.htmUltimately, if it is absolutely necessary to program asynchronous WinInet using the MFC classes, it is possible to do so. The ASYNCGET sample demonstrates some of the necessary techniques in a simple FTP download application. It also demonstrates some common methods for synchronizing asynchronous events as well as how to mix direct WinInet calls with MFC WinInet calls. ASYNCGET is designed as a simple FTP file retrieval application. It proceeds in two phases - the connection phase and the download phase. The connection phase is a representation of an FTP connection; an FTP connection involves transparently connecting to an FTP server and then logging into that server. The download phase involves sending commands to the FTP server to request a file and then receiving that file to the local computer. In ASYNCGET, the download phase cannot begin until the connection phase is completed. Just to be confusing, ASYNCGET also refers to a "download" as the full process of proceeding through both phases. ASYNCGET allows for the download of only one file at a time, even though WinInet supports multiple concurrent downloads for some connection types. In addition, functionality has been added which allows the user to halt at any point in the download process. Following is a list of the main problems that ASYNCGET addresses:
Keywords : AXSDKWinInet kbprg Version : 4.2 Platform : NT WINDOWS Solution Type : kbcode |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |