I use InternetOpen with the INTERNET_FLAG_ASYNC flag, for asynchronous
communications:
InternetOpen (OPenName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL,
INTERNET_FLAG_ASYNC);
and prior to calling InternetReadFileEx, I make sure I have a buffer to
store the data:
BYTE* Buffer = new BYTE[8096];
Then I set the buffer info in the INTERNET_BUFFERS structure:
INTERNET_BUFFERS* m_pInternetBuffer = new INTERNET_BUFFERS;
m_pInternetBuffer->dwStructSize = sizeof(INTERNET_BUFFERS);
m_pInternetBuffer->dwBufferLength = 8096;
m_pInternetBuffer->lpvBuffer = Buffer;
When I call InternetReadFileEx, I also use the IRF_ASYNC flag:
InternetReadFileEx(urlConnection, m_pInternetBuffer, IRF_ASYNC,
callingContext );
It works mostly fine: I can see that request is sent, data is received (the
callback function gets called, etc.), and I can also see that data actually
gets copied into the lpvBuffer buffer, and it is the right data. My problem
is that dwBufferLenght does not get updated accordingly...
My understanding of WinInet is that the value of dwBufferLenght is supposed
to decrease each time data is read, so that you stop requesting data when
your buffer is full. In my program, the dwBufferLenght value is not
modified by InternetReadFileEx, so my program keeps looping in the reading
loop.
Any way to solve that? Or any other way to find out how many bytes were
read by InternetReadFileEx?
I am using windows XP pro, version 2002, SP2, and IE version
6.0.2900.2180.xpsp_sp2_rtm.040803-2158
Any help appreciated!