Hi,
I've got my internet connection working, and everything sends fine. No I wanted to read back the data from the site I connect to, but I keep getting an ERROR_INVALID_PARAMETER. I've tried some different combinations of parameters for the InternetReadFile function, but to no avail. Maybe it is something else I am doing wrong My code so far is:
DWORD dwContext = 1;
char errorMsg[100];
hWaitForHandleCreation = CreateEvent(NULL, TRUE, TRUE, NULL);
hWaitForCompletedRequest = CreateEvent(NULL, TRUE, TRUE, NULL);
ResetEvent(hWaitForHandleCreation);
ResetEvent(hWaitForCompletedRequest);
// Open the internet connection and send the URLhttp = InternetOpen(L
"CeHttp",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,INTERNET_FLAG_ASYNC); if (http == NULL){
_snprintf(errorMsg,100,
"Internet Open Error: %d",GetLastError());MessageBox(NULL,CA2W(errorMsg),L
"Check",MB_OK);}
InternetSetStatusCallback(http,(INTERNET_STATUS_CALLBACK)InternetCallback);
httpRequest = InternetOpenUrl(http,CA2W(url),NULL,0,INTERNET_FLAG_RELOAD
,dwContext); // Wait until handle is createdWaitForSingleObject(hWaitForHandleCreation,2000);
httpRequest = hResultHandle;
DWORD waitForRequest = WaitForSingleObject(hWaitForCompletedRequest,5000);
// Check if the connection worked and see if there is any old data to send if (httpRequest != NULL && waitForRequest != WAIT_TIMEOUT){
LPCWSTR buffer[4096];
LPDWORD lpdwContext = 0;
boolean bOk = InternetReadFile(httpRequest,&buffer,5,lpdwContext);
if (!bOk){
_snprintf(errorMsg,100,"Internet Read File Error: %d",GetLastError());
MessageBox(NULL,CA2W(errorMsg),L"Check",MB_OK);
}
else
{
_snprintf(errorMsg,100,
"%s",buffer);MessageBox(NULL,CA2W(errorMsg),L
"Check",MB_OK);}
}
The connection is always fine, but I always get:
Internet Read File Error: 87
Which is ERROR_INVALID_PARAMETER.
Any ideas, please

InternetReadFile errors
PaulCzy
For anyone who cares, I fixed it myself. InternetReadFile is synchronous, which means I had to use InternetReadFileEx for asynchronous. For some crazy reason, this was never implemented in the InternetReadFileExW and InternetReadFileExA, but only in the InternetReadFileExA way. So I forced it to run this function, added some waits for the async returns, and it worked like a charm. Here is my code that works (just putting it in from the code before):
...
if
(httpRequest != NULL && waitForRequest != WAIT_TIMEOUT){
// Check the response from online ResetEvent(hWaitForResponseRequest); char buffer[50];DWORD dwRead = 0;
INTERNET_BUFFERS ib = {
sizeof(INTERNET_BUFFERS) };ib.lpvBuffer = buffer;
ib.dwBufferLength =
sizeof(buffer); // Get then wait for the responseInternetReadFileExA(httpRequest, (LPINTERNET_BUFFERSA)&ib, IRF_ASYNC, dwContext);
waitForRequest = WaitForSingleObject(hWaitForResponseRequest, 5000);
// If it got a response, check what it was and perform the appropriate action if (waitForRequest != WAIT_TIMEOUT){
// It worked - I now have upto 50 characters of the input in ib.lpvBuffer } else{
// It failed
}........
}