Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

InternetCloseHandle problem

218 views
Skip to first unread message

Arthur van Rooijen

unread,
Nov 9, 1999, 3:00:00 AM11/9/99
to
Hi,

I'm using the the wininet api asynchronously. Accoording to the manual I can
use InternetCloseHandle to close the connection and stop any pending
requests.

When I use InternetCloseHandle on the connection handle after I started a
FtpGetFile I sometimes get an Access Violation error in Wininet.dll.
It looks like I only get this error when I call InterNetCloseHandle sortly
after I get the INTERNET_STATUS_HANDLE_CREATED message in my Callback
routine. When I call InternetCloseHandle when the download is started it
closes OK without an Access error.

Is there a way to prevent this error because I never know when an user is
going to cancel the download, accoording to Murphy's law this will hapen
just after the handle is created ;-).

I use the dwContext variable to store all my connection handles. This
dwContext variable is a global structure. I noticed when I change a handle
in the Callback routine it is not immediately available in the other
routines. It will take a short moment until I can use it outsite the
callback routine WHY ??

eg
struct gContext {
HINTERNET hConnection
}

in the call back:
case INTERNET_STATUS_HANDLE_CREATED:
// Use this function to set Context handle

cpContext->hConnection=(HINTERNET)LPINTERNET_ASYNC_RESULT(lpvStatusInformati
on)->dwResult;

in the code of the cancel button:
if(gContext.hConnection){
bRet=InternetCloseHandle(gContext.hConnection);
}
When this code is called sortly after the handle is set in the callback
routine this code will fail because
gContext.hConnection=0. When I wait a while gContext.hConnection will have
the correct value.


I have not a lot of experience with callback routines, so maybe I'm
overlooking someting

Arthur

Thomas Muhr

unread,
Nov 9, 1999, 3:00:00 AM11/9/99
to
Arthur,
while you can store the handle after HandleCreated, you should wait until
RequestCompleted before relying on it being valid. This is the place where you
can signal semaphores to let your app know that it can procede with the next
step.
At least this is my approach with opening a connection.

- Thomas
Arthur van Rooijen <in...@wxs.nl> wrote:
: Hi,

: cpContext->hConnection=(HINTERNET)LPINTERNET_ASYNC_RESULT(lpvStatusInformati
: on)->dwResult;

: Arthur

--
___________________________________________________________________
Dipl.-Psych. Dipl.-Inform. Thomas Muhr (mu...@atlasti.de)
Scientific Software Development - Internet: http://www.atlasti.de

0 new messages