Hi,
I m trying to access the internet in the asynchronous mode for wince 4.2 smartphone 2003 SE using VS2005. I have already tested the synchronous mode for operation on the emulator. However if I try to download the same URL in asynchronous mode, InternetOpenUrl() API call fails with error code as ERROR_IO_PENDING. I have tried out almost all the code samples on the internet (their happen to be only a couple of them it seems). But still this error is very unexpected as the same URL opens in the synchronous mode. Pls take a look at my code here :
the url i pass to this function is http://10.20.40.1/foo.html
Any help on this would be highly appreciated
int CInternetData::IssueHttpRequestAsync(LPCTSTR lpszUrl,LPTSTR lpResponse)
{
HINTERNET hOpen = NULL , hRequest = NULL;
TCHAR lpCanonicalUrl[500];
DWORD dwSize = 0;
DWORD dwLastError;
// Initialize the use of the Windows CE Internet functions.
hOpen = InternetOpen (TEXT("CeHttp"), INTERNET_OPEN_TYPE_PRECONFIG,NULL, 0, INTERNET_FLAG_ASYNC);
if (!hOpen)
{
wsprintf (szErrMsg, TEXT("%s: %d"), TEXT("InternetApi : InternetOpen : "),
GetLastError());
return ERROR_INTERNET_OPEN;
}
INTERNET_STATUS_CALLBACK statusCallback = InternetSetStatusCallback(hOpen,InternetCallbackFunc);
if(statusCallback == INTERNET_INVALID_STATUS_CALLBACK)
{
wsprintf (szErrMsg, TEXT("%s: %d"), TEXT("InternetData : InternetSetStatusCallback: "),
GetLastError());
return ERROR_INTERNETCANONICALIZEURL;
}
DWORD dwContext = 1;
if (!(hRequest = InternetOpenUrl (hOpen, lpszUrl, NULL, 0,INTERNET_FLAG_RELOAD, dwContext )))
//IT FAILS HERE
{
dwLastError=GetLastError();
if(dwLastError != ERROR_IO_PENDING)
{
wsprintf (szErrMsg, TEXT("%s:%d"), TEXT("InternetData : InternetOpenUrl : "),dwLastError);
InternetCloseHandle(hOpen);
return ERROR_INTERNET_OPEN_URL;
}
}
char buffer[4096];
TCHAR bufferW[4096];
INTERNET_BUFFERS ib;
ib.dwStructSize = sizeof(ib);
ib.lpvBuffer = (LPVOID)buffer;
ib.dwBufferLength = 4096*sizeof(char);
bool bOk = InternetReadFileEx(hRequest,&ib,IRF_ASYNC,dwContext);
if(!bOk && GetLastError()==ERROR_IO_PENDING);
else
{
dwSize = MultiByteToWideChar (CP_ACP, 0, buffer, -1, NULL, 0);
MultiByteToWideChar (CP_ACP, 0, buffer, -1, bufferW, dwSize);
_tcscat(lpResponse,(LPCTSTR)bufferW);
}
while( bOk && ib.dwBufferLength!=0 )
{
bOk = InternetReadFileEx( hRequest, &ib, IRF_ASYNC, (LPARAM)this );
if(!bOk && GetLastError()==ERROR_IO_PENDING);
else
{
dwSize = MultiByteToWideChar (CP_ACP, 0, buffer, -1, NULL, 0);
MultiByteToWideChar (CP_ACP, 0, buffer, -1, bufferW, dwSize);
_tcscat(lpResponse,(LPCTSTR)bufferW);
}
}
InternetCloseHandle(hRequest);
InternetSetStatusCallback(hOpen,NULL);
InternetCloseHandle(hOpen);
return SUCCESSFUL;
}

InternetOpenUrl() fails with ERROR_IO_PENDING in asynchronous mode
Jamie Thomson
Hi,
I'm having the same problem with asynchronous WinInet under Windows Mobile.
After a lot of struggle I got to the point where I was trying to read some data using
InternetReadFileEx. The problem is it never reads anything and GetLast error reports err 120, I think = CALL_NOT_IMPLEMENTED_ON SYSTEM.
How did you get past that one
Trying to read using InternetReadFile instead returns error 12019 or something meaning Handle_in_Wrongstate.
Would you please send me your code snibbet or explain how you got it working.
Thanks in advance
CK-INLINE
Dietz
Can I see the code please It seems I have the same problems.
Thanks in advance.
Robert Hoath
Finally after 3 days of headscrewing i have been able to write and test code for asynchronous internet access. This thread can be considered to be closed now. Anybody if needs the code can get it from me.
Vishal
Al-Arabi
Hi Vishal,
Can you please send me the asynch code.
I will really appreciate it.
Thanks
Gaurav Kapoor
RaviKanthReddy
Hi,
I think the async mode operation fails with the error when ever it can't complete the request immediately. This is normal async behaviour - it should return when it can't complete the work immediately. You need to register a callback function and wait for notifications from the framework about the pending connection. Handle the following notifications
INTERNET_STATUS_HANDLE_CREATED : Save the connection Handle here, as you must have got a NULL on API call.INTERNET_STATUS_REQUEST_COMPLETE: ensures that the connection is complete and you can proceed further normally.Hope this helps.
Thanks
meighlough
Thanx Avinash. You let me know what I was missing. I can just hope I have been able to fix this. But now theres a new problem. I have made a new thread for it titled "InternetReadFileEx() function returns error code 12018" in the same forum. PLEASE check that out.
However I sincerely feel that the real fat culprit here is the incomprehensive documentation and the lack of good and reliable code samples that makes lives of people like us HELL to work on Windows platform and to top it all using this 4.5GB hugely buggy and inefficient dinosaur called as VS2005. Believe me, make the documentation more fuller and reasonable and we wont even need forums like these where we can put up questions and just "hope" for replies from guys like you. I have been coding in native for windows smartphone 2003 SE for more than 2.5 months and the experience has been nothing less than frustating.
A "now frustated with windows smartphone" coder
Vishal
GrahamY
Hi,
May be having a look at the following links shall help.
http://msdn.microsoft.com/library/default.asp url=/archive/en-us/dnarwebtool/html/msdn_advftp.asp (look at the callback section and the meaning of function parameters for the callback)
http://www.codeproject.com/internet/asyncwininet.asp
Hope this helps.