IHttpResponse::WriteEntityChunks Method

IIS 7.0

Appends one or more HTTP_DATA_CHUNK structures to the response body.

virtual HRESULT WriteEntityChunks(
   IN HTTP_DATA_CHUNK* pDataChunks,
   IN DWORD nChunks,
   IN BOOL fAsync,
   IN BOOL fMoreData,
   OUT DWORD* pcbSent,
   OUT BOOL* pfCompletionExpected = NULL
) = 0;


[IN] A pointer to one or more HTTP_DATA_CHUNK structures.


[IN] A DWORD that contains the number of chunks pointed to by pDataChunks.


[IN] true if the method should complete asynchronously; otherwise, false.


[IN] true if more data is to be sent in the response; false if this is the last data.


[OUT] The number of bytes that were sent to the client if the call completes synchronously.


[OUT] true if an asynchronous completion is pending for this call; otherwise, false.

An HRESULT. Possible values include, but are not limited to, those in the following table.




Indicates that the operation was successful.


Indicates that the parameter is not valid (for example, the pDataChunks pointer is set to NULL).


Indicates that there is insufficient memory to perform the operation.


More than 65535 chunks have been added to the response.

Developers can use the WriteEntityChunks method to insert a single HTTP_DATA_CHUNK structure or an array of HTTP_DATA_CHUNK structures into the response body. If the operation has completed synchronously, the pcbSent parameter will receive the number of bytes that were inserted into the response.

If buffering is turned on, the WriteEntityChunks method will create a copy of any HTTP_DATA_CHUNK structures, thereby duplicating the underlying data so that it does not need to be preserved. If buffering is turned off, or the response buffer limit is reached, the WriteEntityChunks method will also flush the response. If buffering is off and the fAsync parameter is true, the memory must be preserved until the request completes.

You can configure a WriteEntityChunks operation to complete asynchronously by setting the fAsync parameter to true. In this situation, the WriteEntityChunks method will return immediately to the caller, and the pcbSent parameter will not receive the number of bytes that were inserted into the response. If buffering is disabled and the fAsync parameter is true, the memory for the pDataChunks parameter must be persisted until the asynchronous call completes.

A maximum of 65535 chunks (64 KB minus 1) can be written to a request.


The following example demonstrates how to use the WriteEntityChunks method to create an HTTP module that inserts an array of two data chunks into the response. The example then returns the response to a Web client.

Your module must export the RegisterModule function. You can export this function by creating a module definition (.def) file for your project, or you can compile the module by using the /EXPORT:RegisterModule switch. For more information, see Walkthrough: Creating a Request-Level HTTP Module By Using Native Code.

You can optionally compile the code by using the __stdcall (/Gz) calling convention instead of explicitly declaring the calling convention for each function.





  • IIS 7.0 on Windows Vista

  • IIS 7.5 on Windows 7

  • IIS 8.0 on Windows 8

  • IIS 10.0 on Windows 10


  • IIS 7.0 on Windows Server 2008

  • IIS 7.5 on Windows Server 2008 R2

  • IIS 8.0 on Windows Server 2012

  • IIS 8.5 on Windows Server 2012 R2

  • IIS 10.0 on Windows Server 2016 Technical Preview


  • IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0

  • IIS Express 7.5, IIS Express 8.0, IIS Express 10.0