Hi! [Here](https://msdn.microsoft.com/en-us/library/windows/desktop/aa384102(v=vs.85).aspx) Microsoft recommends the following trick:
```
WinHttpQueryHeaders( hRequest, WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX, NULL,
&dwSize, WINHTTP_NO_HEADER_INDEX);
// Allocate memory for the buffer.
if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER )
{
lpOutBuffer = new WCHAR[dwSize/sizeof(WCHAR)];
// Now, use WinHttpQueryHeaders to retrieve the header.
bResults = WinHttpQueryHeaders( hRequest,
WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX,
lpOutBuffer, &dwSize,
WINHTTP_NO_HEADER_INDEX);
}
```
We found that if the file has
```
#include <vld.h>
...
VLDDisable();
..
VLDEnable();
```
The function GetLastError() of Windows API returns 0 instead of ERROR_INSUFFICIENT_BUFFER. __Somehow the last error is cleared by VLD__. We found a workaround, we use
```
if(dwSize > 0 )
```
instead of
```
if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER )
```
But others may suffer. Thanks, Levi
```
WinHttpQueryHeaders( hRequest, WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX, NULL,
&dwSize, WINHTTP_NO_HEADER_INDEX);
// Allocate memory for the buffer.
if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER )
{
lpOutBuffer = new WCHAR[dwSize/sizeof(WCHAR)];
// Now, use WinHttpQueryHeaders to retrieve the header.
bResults = WinHttpQueryHeaders( hRequest,
WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX,
lpOutBuffer, &dwSize,
WINHTTP_NO_HEADER_INDEX);
}
```
We found that if the file has
```
#include <vld.h>
...
VLDDisable();
..
VLDEnable();
```
The function GetLastError() of Windows API returns 0 instead of ERROR_INSUFFICIENT_BUFFER. __Somehow the last error is cleared by VLD__. We found a workaround, we use
```
if(dwSize > 0 )
```
instead of
```
if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER )
```
But others may suffer. Thanks, Levi