Dear Windows 8 Developers ,

can anybody help me to solve this problem.


Environment:


server : Tomcat HttpNio11 connector ( CometProcessor servlet).
Agent : Win htttp Asynchronous handling.

Error in EventViewer :

Log Name: Application
Source: Application Error
Date: 9/5/2012 1:08:48 AM
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Computer: ComputerName
Description:
Faulting application name: My.exe, version: 1.0.0.1, time stamp: 0x5045a901
Faulting module name: WINHTTP.dll, version: 6.2.8400.0, time stamp: 0x4fb6f3d7

Exception code: 0xc0000005
Fault offset: 0x0000a93d
Faulting process id: 0xef0
Faulting application start time: 0x01cd8ad4e681bcd8
Faulting application path: Path\My.exe
Faulting module path: C:\Windows\SYSTEM32\WINHTTP.dll
Report Id: 250741c3-f6c8-11e1-bbc2-0024d7e008a4
Faulting package full name:
Faulting package-relative application ID:

For you Ref :

I Added below function in WinHttpSetStatusCallback to add this callback reference. After i get event of WINHTTP_CALLBACK_STATUS_READ_COMPLETE to readthe complete Buffer, I want to read again , so i use WinHttpQueryDataAvailable(hInternet, NULL) ; It returns Error Code with 6 and Application also Terminated, After the AsyncHttpNioCallback function finish. But above scenario working fine except Windows 8 and windows server 2012 operating system.


Here is my AsyncHttp Call Back code for your ref, bold to Indicate the fault line.

Code:
void CAsyncHttpNio::AsyncHttpNioCallback(HINTERNET hInternet, DWORD_PTR dwContext,DWORD dwInternetStatus,LPVOID lpvStatusInformation,DWORD dwStatusInformationLength) 
{
    CAsyncHttpNio    *pthAsyncHttp = NULL;   
    WINHTTP_ASYNC_RESULT *pAR;
    TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : Start\n");
    
    pthAsyncHttp = (CAsyncHttpNio *)dwContext;
    
    try
    {
        switch (dwInternetStatus)
        {
        case WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER\n");
            pAR = (WINHTTP_ASYNC_RESULT *)lpvStatusInformation;
        //    pthAsyncHttp->m_hConnect = (HINTERNET)pAR->dwResult;
            break;
        case WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER\n");
            break;
        case WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE\n");
            if(WinHttpReceiveResponse(hInternet,NULL) == FALSE)
            {
                pthAsyncHttp->m_dwerr = GetLastError();
                TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] :WinHttpReceiveResponse ErrorCode : %d\n",pthAsyncHttp->m_dwerr);
                HttpGetLastError(pthAsyncHttp->m_dwerr);
                //Close();
            }
            
            break;

        case WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE\n");
            pthAsyncHttp->Header(hInternet);
            pthAsyncHttp->QueryData(hInternet);
            break;
        case WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE:
            

            pthAsyncHttp->m_dwReadDatasize = *((LPDWORD)lpvStatusInformation);
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE DataSize - %d\n",pthAsyncHttp->m_dwReadDatasize);

            if(pthAsyncHttp->m_dwReadDatasize != 0)
            {
                pthAsyncHttp->ReadData(hInternet);
            }
            else
            {
                pthAsyncHttp->Register(pthAsyncHttp->m_strSenderID,pthAsyncHttp->m_strSessionID,EM_NIO_ACTION_REREGISTER);
            }
            
            break;
            
        case WINHTTP_CALLBACK_STATUS_READ_COMPLETE:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_READ_COMPLETE\n");
        
            pthAsyncHttp->ReadCompleteBuffer((LPSTR)lpvStatusInformation,dwStatusInformationLength);
            
            pthAsyncHttp->QueryData(hInternet);     // if i comment this code.. process won't get crash issue. but i can't read further.
 
            TRACE("[CAsyncHttpNio11::AsyncHttpNioCallback] :Query Data End\n");
            
            break;

        case WINHTTP_CALLBACK_STATUS_REDIRECT:
            TRACE("[CAsyncHttpNio11::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_REDIRECT - %d\n",dwStatusInformationLength);            
            break;

        case WINHTTP_CALLBACK_STATUS_REQUEST_ERROR:

            pAR = (WINHTTP_ASYNC_RESULT *)lpvStatusInformation;
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_REQUEST_ERROR - %d\n",pAR->dwError);
            
            if(((!bIsStop)&&(pAR->dwError == 12017))||(pAR->dwError == 12002)||(pAR->dwError == 12152))
            {
                pthAsyncHttp->Register(pthAsyncHttp->m_strSenderID,pthAsyncHttp->m_strSessionID,EM_NIO_ACTION_REREGISTER);
            }
            break;
        case WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE: 
            TRACE("[CAsyncHttpNio11::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE\n");

            pthAsyncHttp->Header(hInternet);
            pthAsyncHttp->QueryData(hInternet);

            break;
        
            
        case WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED:  
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED\n");
            break;;
        case WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED:  
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED\n");
            pthAsyncHttp->Register(pthAsyncHttp->m_strSenderID,pthAsyncHttp->m_strSessionID,EM_NIO_ACTION_REREGISTER);
            break;
        case WINHTTP_CALLBACK_STATUS_RESOLVING_NAME:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED\n");
            break;
        case WINHTTP_CALLBACK_STATUS_NAME_RESOLVED:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_NAME_RESOLVED\n");
            break;
        case WINHTTP_CALLBACK_STATUS_SENDING_REQUEST:            
            WinHttpReceiveResponse(pthAsyncHttp->m_hRequest,NULL);
            break;
        case WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION \n");
            //WinHttpReceiveResponse(pthAsyncHttp->m_hRequest,NULL);
            break;
        default:
            TRACE("[CAsyncHttpNio::AsyncHttpNioCallback] : Unknown/unhandled callback : 0x%X\n",dwInternetStatus);
            
            break;
        }
        TRACE("[CAsyncHttpNio11::AsyncHttpNioCallback] : End\n");
        return;
           
    }
    catch(...)
    {
        TRACE("[CAsyncHttpNio11::AsyncHttpNioCallback] : Exception\n");
        return;
    }
}
Thanks

Arunkumar . U