home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activedocument / range / range.h < prev    next >
C/C++ Source or Header  |  1996-05-23  |  5KB  |  126 lines

  1. /*===========================================================================
  2. Copyright 1996 Microsoft Corporation.  All Rights Reserved.
  3.  
  4. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  5. ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  6. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  7. PARTICULAR PURPOSE.
  8.  
  9. OVERVIEW OF INTERFACE
  10.  
  11. The client calls HttpReadRequest to specify the URL, a callback function, 
  12. and an optional array of read ranges.  First, the callback will be notified
  13. of the http response code, content length, last modified time, whether 
  14. ranges are supported by the server, and whether the file is from the cache.  
  15. Next, it may be called repeatedly with data which must be processed during the 
  16. call.  Finally, it will indicate completion and an error if any.  Within the
  17. callback, a client can initiate a new HttpReadRequest and/or return FALSE to
  18. stop the current request.
  19.  
  20. All ActiveX controls can use this interface.  Other applications must satisfy
  21. some requirements due to an implicit dependency on URL moniker.  The client
  22. thread must have a message loop.  Before calling HttpReadRequest, the client
  23. process must have called CoInitialize or OleInitialize.  After exiting the
  24. message loop, the client process must call CoUninitialize or OleUninitialize.
  25. ===========================================================================*/
  26.  
  27. #ifndef _RANGE_
  28. #define _RANGE_
  29.  
  30. #include <windows.h>
  31. #include <objbase.h>
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36.  
  37. // ===========================================================================
  38. // Callback parameter structure and prototype
  39. // ===========================================================================
  40.  
  41. // Callback Types:
  42. typedef enum 
  43. {
  44.     REQUESTCB_STARTED  = 0,
  45.     REQUESTCB_DATA     = 1,
  46.     REQUESTCB_DONE     = 2,
  47. }
  48.     HTTP_REQUESTCB_TYPE;
  49.  
  50. // Callback parameters: valid only during the current call.
  51. typedef struct
  52. {
  53.     DWORD  cbStruct;       // will be sizeof(HTTP_CALLBACK_PARAM)
  54.     DWORD  dwRequestCtx;   // context passed in to HttpReadRequest
  55.     HTTP_REQUESTCB_TYPE CallbackType;   // callback type as defined above
  56.     
  57.     union
  58.     {
  59.         struct // fields used if CallbackType == REQUESTCB_STARTED
  60.         {
  61.             DWORD       fdwRequestFlags;  // fields as defined below
  62.             DWORD       dwResponseCode;   // status code (0 if unknown)
  63.             SYSTEMTIME* pstLastModified;  // last modified (NULL if unknown)
  64.             DWORD       dwContentLength;  // content length (0 if unknown)
  65.         };
  66.  
  67.         struct // fields used if CallbackType == REQUESTCB_DATA
  68.         {
  69.             DWORD       dwDataOffset;     // offset of data
  70.             LPVOID      lpDataBuffer;     // pointer to data
  71.             DWORD       cbDataLength;     // amount of data
  72.         };
  73.  
  74.         struct // fields used if CallbackType == REQUESTCB_DONE
  75.         {
  76.             HRESULT     hrRequest;        // values defined in urlmon.h
  77.         };
  78.     };
  79. }
  80.     HTTP_REQUESTCB_PARAM, *PHTTP_REQUESTCB_PARAM;
  81.  
  82. // Fields for HTTP_REQUESTCB_PARAM.fdwRequestFlags:
  83. #define HTTP_REQUEST_FROM_CACHE       1
  84. #define HTTP_REQUEST_ACCEPT_RANGES    2 
  85.  
  86. // Callback function supplied by client:
  87. typedef BOOL (*PFN_REQUESTCB) (PHTTP_REQUESTCB_PARAM);
  88.  
  89. // ===========================================================================
  90. // HttpReadRequest parameter structure and prototype
  91. // ===========================================================================
  92.  
  93. // Structure for specifying a read range:
  94. typedef struct
  95. {
  96.     DWORD dwOffset;     // offset of data within the URL
  97.     DWORD dwSize;       // amount of data (0 means until end of file)
  98. }
  99.     HTTP_REQUEST_RANGE, *PHTTP_REQUEST_RANGE;
  100.  
  101. // Read request parameters must remain valid until REQUEST_COMPLETE:
  102. typedef struct
  103. {
  104.     DWORD               cbStruct;        // must be sizeof(HTTP_REQUEST_PARAM)
  105.      LPVOID              punkOuter;       // controlling IUnknown (may be NULL)
  106.     PCSTR               pszUrl;          // URL to request via http
  107.     PFN_REQUESTCB       pfnRequestCB;    // request callback function
  108.     DWORD               dwRequestCtx;    // context to pass to callback
  109.  
  110.     // Optional fields for specifying ranges, otherwise set all to 0:
  111.     PHTTP_REQUEST_RANGE pRanges;                // array of read ranges
  112.     DWORD               cRanges;                // number of ranges
  113.     SYSTEMTIME*         pstUnlessModifiedSince; // unless-modified-since time
  114. }
  115.     HTTP_REQUEST_PARAM, *PHTTP_REQUEST_PARAM;
  116.  
  117. // Function called by client to initiate http read request.
  118. BOOL HttpReadRequest    (PHTTP_REQUEST_PARAM); // try cache first
  119. BOOL HttpReadFromServer (PHTTP_REQUEST_PARAM); // bypass cache
  120.  
  121. #ifdef __cplusplus
  122. } // extern "C" {
  123. #endif
  124.  
  125. #endif // _RANGE_
  126.