Discussion:
WinHttpReadData problem
(too old to reply)
gunnerjay
2009-03-07 17:53:01 UTC
Permalink
I am trying to use WinHTTP 5.1 in an asynchronous manner to be able to
retrieve XML data using a standard GET with URL.

In doing so I have an callback method that handles the various status
changes, with the status in question being
WINHTTP_CALLBACK_STATUS_READ_COMPLETE. In my problem case. the
dwStatusInformationLength parameter is 0, which means I the request is
completed. I proceed to call WinHttpCloseHandle on the request handle, and
expect a callback in the same function with
WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING as the status. However, I crash with
an exception, where winhttp is trying to access memory address 0x00000000.
Looking at the call stack, this appears to be on exit of the previous call to
WinHttpReadData in the same WINHTTP_CALLBACK_STATUS_READ_COMPLETE that it is
unwinding from. What is strange is that all the other interactions up to
this point have been fine (my entire request is completed and I get the data
I expect, no I just want to shut down the sequence but am having a problem).

So the code snippit in my callback looks like:

MyContext * pContext = (MyContext*)dwContext;
case WINHTTP_CALLBACK_STATUS_READ_COMPLETE:
{
if (dwStatusInfromationLength != 0)
{
// Copy the new data
pContenxt->m_finalBuffer.AddTo((char*)dwStatusInformation,
dwStatusInformationLength));
// Do the next read, might be more data
if (WinHTTPReadData(pContext->m_request, pContext->m_tempBuffer,
sizeof(pContext), NULL) == FALSE) <<========= CRASH AFTER here
{
//Handle Error
}
}
else
{
// Reading completed, close handle
WinHttpCloseHandle(pContext->m_request);
}
}

so in the code above, it falls through the else case, so there's no more to
read (and my buffer looks fine with the expected content), but that I have
the exception at the pointed at location when it exits.

Any insight/suggestions are much appreciated.
gunnerjay
2009-03-09 17:42:02 UTC
Permalink
Post by gunnerjay
I am trying to use WinHTTP 5.1 in an asynchronous manner to be able to
retrieve XML data using a standard GET with URL.
In doing so I have an callback method that handles the various status
changes, with the status in question being
WINHTTP_CALLBACK_STATUS_READ_COMPLETE. In my problem case. the
dwStatusInformationLength parameter is 0, which means I the request is
completed. I proceed to call WinHttpCloseHandle on the request handle, and
expect a callback in the same function with
WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING as the status. However, I crash with
an exception, where winhttp is trying to access memory address 0x00000000.
Looking at the call stack, this appears to be on exit of the previous call to
WinHttpReadData in the same WINHTTP_CALLBACK_STATUS_READ_COMPLETE that it is
unwinding from. What is strange is that all the other interactions up to
this point have been fine (my entire request is completed and I get the data
I expect, no I just want to shut down the sequence but am having a problem).
MyContext * pContext = (MyContext*)dwContext;
{
if (dwStatusInfromationLength != 0)
{
// Copy the new data
pContenxt->m_finalBuffer.AddTo((char*)dwStatusInformation,
dwStatusInformationLength));
// Do the next read, might be more data
if (WinHTTPReadData(pContext->m_request, pContext->m_tempBuffer,
sizeof(pContext), NULL) == FALSE) <<========= CRASH AFTER here
{
//Handle Error
}
}
else
{
// Reading completed, close handle
WinHttpCloseHandle(pContext->m_request);
}
}
so in the code above, it falls through the else case, so there's no more to
read (and my buffer looks fine with the expected content), but that I have
the exception at the pointed at location when it exits.
Any insight/suggestions are much appreciated.
Noticed a typo, the crash line should say:
if (WinHTTPReadData(pContext->m_request, pContext->m_tempBuffer,
sizeof(pContext->m_tempBuffer), NULL) == FALSE) <<========= CRASH AFTER here
Loading...