Here is the prototype...
Let me explain the problem I am having by showing you a little example:
DWORD lpdwNumberOfBytesRead = 0;
HINTERNET hInternet, hFile;
char url = "http://www.cnn.com"; // whatever -- not important
hInternet = InternetOpen(" ",
NULL, NULL, 0);
MessageBox(hwnd, "Could not open connection", "InternetOpen", MB_OK | MB_ICONERROR);
hFile = InternetOpenUrl(hInternet,
NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NEED_FILE |
if(hFile != NULL)
for( ; ; )
bRetval = InternetReadFile( hFile, lpBuffer, 2000, &lpdwNumberOfBytesRead);
if(bRetval && lpdwNumberOfBytesRead == 0)
// I would include code here to null terminate lpBuffer
Now, in this example, which works perfectly, the third parameter of InternetReadFile is set to equal the size of lpBuffer. But when I set the third parameter, or the number of bytes I want read per call to the InternetReadFile function, to less than the size of lpBuffer -- lets say to 1000 -- I get unwanted results. For instance, with the third parameter set to 1000 the first 1000 bytes of data is written to lpBuffer without a problem, but the remaining 1000 bytes of data, which is suppose to be written when InternetReadFile is called for the second time within the for loop, is not being written to lpBuffer at all. The end result: a file that is suppose to be 2000 bytes long but actually only contains 1000 bytes of data. This is the sort of problem I am having. Does anyone know why?