Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Canceling WinInet calls

Status
Not open for further replies.

apatterno

Programmer
Nov 26, 2002
368
US
Hi, I am using the MFC WinInet classes to retrieve files via HTTP.

I am doing this action in a separate thread, so that the User Interface can remain responsive.

However, I am wondering how I might implement a "Cancel" button for this behavior. A dialog would be displayed during the operation, and the user can click Cancel at any time.

The problem is, how do I cause the operation to stop? The documentation says that TerminateThread should only be used in the most extreme cases. Thus, I'm inclined to believe there's another way.

I have tried testing for a cancel-flag between each step of the operation (e.g., connecting to server, sending the request etc.) but that means the user must wait for that part of the operation to finish.

I'm sure this is possible--I mean, they did it on Internet Explorer for the "Stop" button. Just don't know how to go about doing that.

Thanks in advance.
Will

I REALLY hope that helps.
Will
 
Hi Will,

As far as I am aware WinInet is a high level API that uses blocking sockets. It is intended to simplify tcp/ip development so you don’t have to deal with Sockets etc. Therefore there is no mechanism to Cancel the request once it is started. If you need that level of control you should drop down to the Socket level.

-pete
 
Ok, so that was way wrong. You can do async WinInet. Still reading, I’ll be back….

-pete
 
Try calling CInternetSession::Close() to cancel a blocking call. Let us know if that works.

-pete
 
Well, though it wasn't exactly what I wanted to hear, thank you for that advice.

I suppose I will be spending the next several hours writing an HTTP header parser.

I never liked WinInet anyway. [lol]

Thanks
Will
 
>> writing an HTTP header parser.

I think i have that stuff if you want.

-pete
 
I guess I'd be reinventing the wheel, I'm sure there are a lot of libraries out there already that do this. Well at least I know there's one for Perl.

So then, where can I get this?

I REALLY hope that helps.
Will
 
[lol] well i did reinvent that wheel. I have my own i could give you. If you want to look for a library try searching google for "w3c libw". Also you might look on Boost.org

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top